Let's assume I have a class which contains a dynamically allocated member, as shown below:
class example
{
private:
otherClass * pointer;
public:
example(int foo){ pointer = new otherClass(foo); }
~example(){delete pointer;}
};
//defining template parameter
example template(1);
Now lets assume that I want to dynamically push_back that template object into a vector, as shown below:
std::vector<example> myVector;
for(int i=0; i<5; i++)
myVector.push_back(template);
myVector.erase(myVector.begin());
My question is: How do I prepare the class to handle dynamically allocated pointers? I know I need to overload the copy constructor, but do I also need to overload the copy assignment? what about move constryctor or move assignment? Are there any other precautions that I forgot about?