Thursday, 17 May 2018

Part1:Normal Member Function With Pointers

"Nice One Program"

//RULE
//RUlE2:pointer to object of derived class are compatible with pointer to object of base class
//RULE1:Compiler will igonre the content of pointer and choose the member function of the type of pointer

#include<iostream>
using namespace std;
class base
{
public:
void show()
{cout<<"Base";
}

};

class derv1:public base
{
void show()
{
cout<<"Derived";
}
};

class derv2:public base
{
void show()
{
cout<<"Derived2";
}

};
int main()

derv1 obj1;
derv2 obj2;
base *ptr;

ptr=&obj1;
ptr->show();

ptr=&obj2;
ptr->show();


return 0;

}




No comments:

Post a Comment