class A
{
public:
virtual void display_A(A* obja)
{
cout<<"Class A"<<endl;
}
};
class B:public A
{
public:
void display_A(B* objb)
{
cout<<"Class B"<<endl;
}
};
int main()
{
A AOBJ;
B BOBJ;
A *obja = new B();
obja->display_A(&AOBJ);
obja->display_A(&BOBJ);
return 0;
}
There is a virtual function in class A having parameter as A*
and we are overriding the same function in the derived class B
with parameter B*
.
I have created a pointer obja
(pointer to class A
) which is pointing to derived class object B
. When I am calling the function display_A
with obja
pointer with argument as class A
object pointer and class B
object pointer, I am getting o/p as
Class A
Class A
I am unable to understand why I am getting that o/p.