// TestCPP001.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class man
{
public:
string sName;
man():sName("sName")
{}
virtual void out()
{
cout<<"---man(start)---"<<endl;
cout<<"man:姓名:"<<sName<<endl;
cout<<"---man(end)---"<<endl;
}
};
class student : public man
{
public:
int iYear;
student():iYear(22)
{}
void out()
{
cout<<"------student(start)------"<<endl;
man::out();
cout<<"student:年龄:"<<iYear<<endl;
cout<<"------student(end)------"<<endl;
}
};
class cpc:public man
{
public:
int iYear;
cpc():iYear(11)
{}
void out()
{
cout<<"------cpc(start)------"<<endl;
man::out();
cout<<"cpc:党龄:"<<iYear<<endl;
cout<<"------cpc(end)------"<<endl;
}
};
class stucpc:public student,public cpc
{
public:
int gender;
stucpc():gender(0)
{}
void out()
{
cout<<"------------stucpc(start)------------"<<endl;
student::out();
cpc::out();
cout<<"性别:"<<gender<<endl;
cout<<"------------stucpc(end)------------"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
stucpc sc;
student* pStu = ≻
cpc* pCpc = ≻
man* pMStu = pStu;
man* pMCpc = pCpc;
pStu->out();
pCpc->out();
pMStu->out();
pMCpc->out();
return 0;
}
C++多重继承乱象
最新推荐文章于 2022-11-29 11:11:28 发布