I'm trying to make a copy of a derived class with only a base class pointer.
So if I have:
class BaseClass; //Abstract class with =0 functions
class LeftClass : BaseClass;
class RightClass : BaseClass;
And I have a function that takes a BaseClass as a parameter:
void Function(BaseClass* baseClass)
I want to make a copy of BaseClass, but I want to also copy the extended functionality of LeftClass OR RightClass, but I don't know which one was passed to the function - both are possible.
So I have something like this:
//global
vector<BaseClass*> myVector;
void Function(BaseClass* baseClass)
{
BaseClass* baseClassCopy = new BaseClass(baseClass);
myVector.push_back(baseClassCopy);
}
And then I call the function with a left or right class
int main()
{
LeftClass leftClass;
Function(&leftClass);
LeftClass* ResultOfCopy = myVector.at(0);
}
That code doesn't copy over the entire leftclass as a copy, is there a way to do this I'm overlooking?
Also BaseClass
is abstract, some of the functions are =0
so I can't new one up. Otherwise there is a copy function in the other classes to use.