多重继承派生类的构造函数
#include<iostream>
using namespace std;
class Employee: public Person
{public:
Employee(char *Name, char Sex, int Age, char *Num, char *Clerk, char *Depart, char *Timer): Person(Name, Sex, Age)
{ strcpy(num, Num); strcpy(clerk, Clerk);
strcpy(department, Depart); strcpy(timer, Timer);
cout << " The constructor of derived class Employee is called."<< endl;
}
~ Employee( )
{ cout << " The destructor of derived class Employee is called." << endl; }
void EShow( )
{ cout << " employee's num: " << num << endl;
cout << " clerk: " << clerk << endl;
cout << " department:: " << department << endl;
cout << " timer: " << timer << endl;
}
void EmpShow( )
{ Show( );
cout << " employee's num: " << num << endl;
cout << " clerk: " << clerk << endl;
cout << " department:: " << department << endl;
cout << " timer: " << timer << endl;
}
protected:
char num[8];
char clerk[20];
char department[30];
char timer[11];
};
class GradOnWork: public Graduate, public Employee
{public:
GradOnWork(char *Name, char Sex, int Age, char *Id, char *Date, float Score,
char *Direct, char *Teacher, char *Num, char *Clerk, char *Depart,
char *Timer): Graduate(Name, Sex, Age, Id, Date, Score, Direct,
Teacher), Employee(Name, Sex, Age, Num, Clerk, Depart, Timer)
{ cout << " The constructor of derived class GradOnWork is called."<< endl; }
~GradOnWork( )
{ cout << " The destructor of derived class GradOnWork is called." << endl; }
void GWShow( )
{
cout << " Be the graduate:" << endl;
GradShow( );
cout << " Be the employee:" << endl;
EShow( );
}
};
int main( )
{ GradOnWork gw("Mary", 'F', 19, "20120101001", "2012.09.01", 680, "Computer", "Johnson", "JG01029", "Senior Engineer", "Research Department", "20 years");
gw.GWShow( );
return 0;
}
#include<iostream>
using namespace std;
class Employee: public Person
{public:
Employee(char *Name, char Sex, int Age, char *Num, char *Clerk, char *Depart, char *Timer): Person(Name, Sex, Age)
{ strcpy(num, Num); strcpy(clerk, Clerk);
strcpy(department, Depart); strcpy(timer, Timer);
cout << " The constructor of derived class Employee is called."<< endl;
}
~ Employee( )
{ cout << " The destructor of derived class Employee is called." << endl; }
void EShow( )
{ cout << " employee's num: " << num << endl;
cout << " clerk: " << clerk << endl;
cout << " department:: " << department << endl;
cout << " timer: " << timer << endl;
}
void EmpShow( )
{ Show( );
cout << " employee's num: " << num << endl;
cout << " clerk: " << clerk << endl;
cout << " department:: " << department << endl;
cout << " timer: " << timer << endl;
}
protected:
char num[8];
char clerk[20];
char department[30];
char timer[11];
};
class GradOnWork: public Graduate, public Employee
{public:
GradOnWork(char *Name, char Sex, int Age, char *Id, char *Date, float Score,
char *Direct, char *Teacher, char *Num, char *Clerk, char *Depart,
char *Timer): Graduate(Name, Sex, Age, Id, Date, Score, Direct,
Teacher), Employee(Name, Sex, Age, Num, Clerk, Depart, Timer)
{ cout << " The constructor of derived class GradOnWork is called."<< endl; }
~GradOnWork( )
{ cout << " The destructor of derived class GradOnWork is called." << endl; }
void GWShow( )
{
cout << " Be the graduate:" << endl;
GradShow( );
cout << " Be the employee:" << endl;
EShow( );
}
};
int main( )
{ GradOnWork gw("Mary", 'F', 19, "20120101001", "2012.09.01", 680, "Computer", "Johnson", "JG01029", "Senior Engineer", "Research Department", "20 years");
gw.GWShow( );
return 0;
}