P
Pranav
include <iostream>
#include <unistd.h>
#include <stdlib.h>
class base{
public :
virtual void disp(){ std::cout << "Base Class\n";}
void show(){ std::cout << "Base Show\n"; }
};
class derived
ublic base{
public :
void disp(){ std::cout << "Derived Class\n"; }
void show(){ std::cout << "Derived Show\n";}
};
int main()
{
base *bptr;
derived *dptr = new derived;
bptr = (base *)dptr;
bptr->disp();
return 0;
}
Why does the bptr call derived version?? Even though I type casted
it..,
I know virtual func are called according to the type of object pointed
by the but not according to the type of pointer used to point to the
object,
#include <unistd.h>
#include <stdlib.h>
class base{
public :
virtual void disp(){ std::cout << "Base Class\n";}
void show(){ std::cout << "Base Show\n"; }
};
class derived
public :
void disp(){ std::cout << "Derived Class\n"; }
void show(){ std::cout << "Derived Show\n";}
};
int main()
{
base *bptr;
derived *dptr = new derived;
bptr = (base *)dptr;
bptr->disp();
return 0;
}
Why does the bptr call derived version?? Even though I type casted
it..,
I know virtual func are called according to the type of object pointed
by the but not according to the type of pointer used to point to the
object,