Still battling with Copy Control
I'm having trouble using push_back() on a vector of user defined types. Copy Control is a fascinating issue, but quiet difficult to master.
The class implements, among other things, a constructor taking a reference to a string, a copy constructor and two overloaded assignment operators.
Code:
aClass(const std::string& = "n/a");
aClass(const aClass&);
aClass& operator=(const aClass&);
aClass& operator=(const std::string&);
I then go on to create the vector in main()
Code:
vector<aClass> vec;
vec.insert(vec.end(), "Luigi"); //atempt with insert
vec.push_back("Anna"); //attempt with push_back
I was under the impression that push_back would operate by first creating a new element, then a temporary of aClass using the string constructor, and then use the copy constructor to copy this temporary to the new element.
How can I effectively do this, short of having to define a aClass object to pass as an argument to push_back()?