20120113

How to initialization member in derived constructor

Program in c to learn "member initialization example in derived constructor", memberil.cpp

#include<iostream>
using namespace std;
class cycle
{
protected:
int x;
public:
cycle(int a)
{
x=a;
}
};
class bike
{
protected:
int y;
public:
bike(int b)
{
y=b;
}
};
class car:public cycle,public bike
{
protected:
float m,n;
public:
car(int a, int b, float c, float d):cycle(a), bike(b)
{
m=c;
n=d;
}
void display()
{
cout<<"*********member initialization example in derived constructor******"<<"\n";
cout<<"x,y,z,m and n are initialized to"<<x<<" "<<y<<" "<<m<<" "<<n<<"\n";
}
};

int main()
{
car g(1,2,3.7,4.7);
g.display();
return 0;
}


Previous                             Home                               Next

No comments:

Post a Comment