The following code is giving compilation error as : "cannot convert from 'Cloneable*' to 'AClass*'" in Line 1. As per my knowledge, it deals with the concepts of compile time and run time polymorphism.But I do not have a concrete reasoning on this.Kindly help.
struct Cloneable
{
virtual Cloneable* clone()
{
cout << "Cloneable";
return new Cloneable;
}
virtual ~Cloneable() {}
};
struct AClass : public Cloneable
{
virtual AClass* clone()
{
cout << "AClass";
return new AClass;
}
};
int main()
{
Cloneable* s1 = new AClass;
AClass* s2 = s1->clone(); //Line 1
return 0;
}