class A{
A(){}
virtualvoid pure() = 0;
}
class B : public A{
B() : A() {}
virtualvoid pure() {}
}
void method(A* a2) {}
// ...
A* a1 = new B();
method(a1);
I need a2 to be a deep copy of a1, but if I understand it correctly, then a2 should just be a pointer copy of a1. How do I make a2 be a different instance of B?
You can make the clone function return a B* in class B but when you call the clone function using a A* the return type will of course be A* because that's the return type of A::clone().