Assume that we have these classes:
class BaseClass;//im an abstract base class!
class Derived1 : public BaseClass;
class Derived2 : public BaseClass;
Both classes inherit from BaseClass
, then we have one vector of pointers to BaseClass's
std::vector<BaseClass*> classes;
So now imagine that I want to copy the vector ACTUALLY COPYING THE ELEMENTS OF IT to classes_copy
. So I don't want the pointers of the classes_copy
to point to the same as classes
. I want to create (using new
to allocate, and I will free them later) a new version of everyone. We have one problem here: we don't know if that pointers of BaseClass
points to the Derived1
or the Derived2
class. So, is this possible? If not, what to do? Any suggestions?