What is the difference between virtual clone and clone? I find the following example, it clone derived to base, what is it for?
class Base{
public:
virtual Base* clone() {return new Base(*this);}
int value;
virtual void printme()
{
printf("love mandy %d\n", value);
}
};
class Derived : public Base
{
public:
Base* clone() {return new Derived(*this);}
virtual void printme()
{
printf("derived love mandy %d\n", value);
}
};
Derived der;
der.value = 3;
Base* bas = der.clone();
bas->printme();
GetNumberOfLegs()
is declared asvirtual
in the base class but not in derived classes. – Tapster