I have a question on assigning a derived class object with base class pointer...
class Base
{
void print() { cout<<"Class Base"; }
};
class Derived: public Base
{
void print() { cout<<"class Derived"; }
};
int main()
{
Base b, *bp;
Derived d, *dp;
b.print();
d.print();
bp = d; // why is this a conversion error? getting an error "cannot convert ‘Derived’ to ‘Base*’ in assignment"
bp = new B(); // this works fine...
}
Does it mean that we can only assign a dynamically allocated derived class object to a base class pointer?? why is that so???