Program : constructor, destructor in multiple inheritance


#include<iostream.h>
#include<conio.h>
class base1
{
protected:
    int a;
public:
base1(int x)
{
a=x;
cout<<"Inside base1 constructor"<<endl;
}
~base1()
{
cout<<"Inside base1 destructor"<<endl;
}
};//end of base class

class base2
{
protected:
    int b;
public:
base2(int y)
{
b=y;
cout<<"Inside base2 constructor"<<endl;
}
~base2()
{
cout<<"Inside base2 destructor"<<endl;
}
};//end of derived class
class derived : public base1,public base2
{
int c;
public:
derived(int x,int y,int z):base1(y),base2(z)
{
c=x;
cout<<"Inside derived constructor"<<endl;
}
~derived()
{
cout<<"Inside derived destructor"<<endl;
}
void show()
{
    cout<<"a : "<<a<<" "<<"b : "<<b<<" "<<"c : "<<c<<endl;
}
};//end of derived class
void main()
{
clrscr();
derived obj(3,4,5);
obj.show();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|