📄 person.h
字号:
//Person.h-类定义文件
#ifndef __PERSON_H__
#define __PERSON_H__
#include <iostream.h>
// 在多继承中,由类A,类B1和类B2以及类C组成了类继承的层次结构。
// 其中,A为基类,B1、B2由A派生,C继承B1、B2两个类而得到
// 在该结构中,类C的对象将包含两个类A的子对象。由于类A是派生类C两条
// 继承路径上的一个公共基类,那么这个公共基类将在派生类的对象中产生多个基
// 类子对象。如果要想使这个公共基类在派生类中只产生一个基类子对象,则必须
// 将这个基类设定为虚基类。
class CPerson
{
public:
CPerson();
virtual ~CPerson();
public:
char *m_name; //姓名
int m_age; //年龄
char *m_sex; //性别
};
class CWorker:virtual public CPerson
{
public:
CWorker();
virtual ~CWorker();
public:
char *m_company; //公司
char *m_department;//部门
};
class CStudent:virtual public CPerson
{
public:
CStudent();
virtual ~CStudent();
public:
char *m_school; //学校
};
class CWorkingStudent:public CWorker,public CStudent
{
public:
CWorkingStudent();
virtual ~CWorkingStudent();
public:
};
void main()
{
cout<<"第3题"<<endl<<endl;
CWorkingStudent ws;
cout<<ws.m_name<<" "<<ws.m_school<<" "
<<ws.m_company<<" "<<ws.m_department<<" "<<endl;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -