Derived Class Pointer
#include
#include
class BC
{
public:
int b;
void show()
{
cout<<"\nb="<
}};
class DC:public BC
{
public:
int d;
void show()
{
cout<<"\nb="<
cout<<"\nd="<
}};
void main()
{
clrscr();
BC *bptr;
BC base;
bptr=&base;
bptr->b=100;
bptr->show();
DC derived;
bptr=&derived;
bptr->b=200;
bptr->show();
DC *dptr;
dptr=&derived;
dptr->d=300;
dptr->show();
dptr->d=400;
((DC *)bptr)->d=500;
((DC *)bptr)->show();
cout<<"\n(DC *)bptr->show()";
getch();
}
OUTPUT
b=100
b=200
b=200
d=300
b=200
d=500
(DC *)bptr->show()
No comments:
Post a Comment