------------------------
#include
using namespace std;
class vehicle
{
public:
virtual void useVehicle(){};
};
class ford:public vehicle
{
public:
void useVehicle()
{
cout<<"driving ford"<
};
class tata:public vehicle
{
public:
void useVehicle()
{
cout<<"driving tata"<
};
class family
{
public:
family(){};
vehicle *myVehicle;
void setVehicle(vehicle *v)
{
myVehicle = v;
}
}
void driveVehicle()
{
myVehicle->useVehicle();
}
virtual void display(){cout<<"i am family"<
class father:public family
{
public:
father(){};
~father(){};
void display(){cout<<"I am a father"<
};
class son:public family
{
public:
son(){};
~son(){};
void display(){cout<<"I am a son"<
};
int main(int argc, char *argv[])
{
family *fm = new father();
fm->display();
fm->setVehicle(new ford());
fm->driveVehicle();
delete fm;
}
No comments:
Post a Comment