class Base
{
public:
virtual void print (){cout<<"Base"<<endl;}
};
class Derived :public Base
{
public:
virtual void print (){cout<<"Derived"<<endl;}
};
int main(){
Base *ptrb1=new Base();
//it will print Base
ptrb1->print();
Base *ptrb2=new Derived();
// it will print Derived
ptrb2->print();
Derived *ptrd=NULL;
//what is the difference between 2ways?
//what is the benefit of useing dynamic_cast?
ptrd=dynamic_cast<Derived*>(ptrb2);
ptrd->print();
}
what is the benefit( or difference between) of dynamic_cast if we can make the base class see the members of derived class by adding virtual function and make the base Indicates to obj from derived class