#include<iostream>
using namespace std;
class A
{
public:
A() { cout << "A构" << endl; };
~A() { cout << "A析" << endl; };
};
class B:public A
{
public:
B() { cout << "B构" << endl; };
~B() { cout << "B析" << endl; };
};
class C :public A
{
public:
C() { cout << "C构" << endl; };
~C() { cout << "C析" << endl; };
};
class D :public B, public C
{
public:
D() { cout << "D构" << endl; };
~D() { cout << "D析" << endl; };
};
int main()
{
B b;
C c;
D d;
}
#include<iostream>
using namespace std;
class Student
{
public:
Student(char *number) { Number = number; };
void show() { cout << "code:" << Number << endl; }
private:
char * Number;
};
class GStudent :public Student
{
private:
char *Specialty;
public:
GStudent(char *number, char *specialty) :Student(number) { Specialty = specialty; };
void show()
{
Student::show();
cout << "学生专业:" << Specialty << endl;
}
};
class Teacher
{
private:
char *T_Specialty;
char *T_Number;
public:
Teacher(char *t_number, char *t_specialty)
{
T_Specialty = t_specialty;
T_Number = t_number;
}
void show() { cout << "教师号:" << T_Number << ",专业" << T_Specialty; }
};
class T_GStudent:public GStudent,public Teacher
{
public:
T_GStudent(char *number,char *specialty,char *t_number,char *t_specialty):GStudent(number,specialty),Teacher(t_number,t_specialty){}
void show()
{
cout << "在职研究生信息:" << endl;
GStudent::show();
Teacher::show();
}
};
int main()
{
GStudent gs("1805004425", "通信工程");
Teacher t("1690089","计算机");
gs.show();
t.show();
T_GStudent tg("1805004425", "通信工程", "1690089", "计算机");
tg.show();
}
#include<iostream>
using namespace std;
class B1
{
public:
B1(int i) { cout << "constructing B1" << i << endl; };
~B1() { cout << "destructing B1" << endl; };
};
class B2
{
public:
B2() { cout << "constructing B2" << endl; };
~B2() { cout << "destructing B2" << endl; };
};
class C :public B2, virtual public B1
{
public:
C(int a, int b,int c):B1(a),memberB1(b),j(c){}
private:
int j;
B1 memberB1;
B2 memberB2;
};
int main()
{
C obj(1, 2, 3);
}