Here's my curiosity
#include <vector>
class A {
protected:
int somedata;
public:
A () : somedata (1) {}
A (const A& cpy) : somedata(cpy.somedata) {}
virtual ~A () {}
};
class B : public A {
A* someobj;
std::vector <A*> vec;
public:
typedef std::vector<A*>::iterator It;
It i;
B() : someobj(NULL) {}
B (int x) : A(), someobj(new A()),vec (std::vector<A*>(x,new A())) ,i(vec.begin()) {}
//B (const B& cpy) : A(cpy), someobj(new A(*cpy.someobj)), vec(cpy.vec) {} //will the default copy constructor do or must i do something like the following:
B (const B& cpy) : A(cpy), someobj(new A(*cpy.someobj)) {
std::vector<A*>::const_iterator o=cpy.vec.begin();
for (i=vec.begin();i!=vec.end();++i,++o) {
(*i)=new A(**o);
}
}
~B () {
for (i=vec.begin();i!=vec.end();++i) {
delete (*i);
}
delete someobj;
}
};
Thank you