Posted by : Sushanth Thursday 17 December 2015

class Base
{
public:
virtual void f1(){cout<<"Base F1"<<endl;}
void f2(){f1();}
};
class Derived:public Base
{
public:
void f1(){cout<<"derived F1"<<endl;}
};
int main()
{
Base *b;
Derived d;
b = &d;
d.f2();
return 0;
}
To call a method in derived class from Base class,declare the method in derived Class as virtual in base class and call that method using upcasted pointer of derived class.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Technical Articles - Skyblue - Powered by Blogger - Designed by Johanes Djogan -