#include<iostream>
using namespace std;
typedef int NET2K1;
enum COLOR{red,green,blue,yellow,white,black,brown};
class net2k
{
public:
net2k(COLOR color,NET2K1 height);
virtual ~net2k(){cout<<"第一个类的析构函数!/n";}
virtual void windows()const {cout<<"第一个类的第一个虚函数!";}
virtual NET2K1 getheight() const{return itsheight;}
virtual COLOR getcolor() const {return itscolor;}
private:
NET2K1 itsheight;
COLOR itscolor;
}; //第一个类
net2k::net2k(COLOR color,NET2K1 height):
itscolor(color),itsheight(height) // 初始化变量
{
cout<<"第一个类初始化变量/n";
}
class bird //第二个类的声明开始
{
public:
bird(COLOR,bool);
virtual ~bird() {cout<<"第二个类的析构函数/n";}
virtual void chirp()const {cout<<"第二个类虚函数";}
virtual void fly()const
{
cout<<"第二个类的第二个有virtual的构造函数-虚函数!";
}
virtual COLOR getcolor()const {return itscolor;}
virtual bool getmigration()const {return itsmigration;}
private:
COLOR itscolor;
bool itsmigration;
};
bird::bird(COLOR color,bool migrates):
itscolor(color),itsmigration(migrates)
{
cout<<"第二个类初始化变量/n";
}
class pegasus:public net2k,public bird //从多个基类中派生
{
public:
void chirp()const{windows();} //覆盖第二个基类的虚构造函数
pegasus(COLOR,NET2K1,bool,long);
~pegasus(){cout<<"派生类的析构函数/n";}
virtual long getnumberbelievers() const
{
return itsnumberbelievers;
}
private:
long itsnumberbelievers;
};
pegasus::pegasus(
COLOR acolor,
NET2K1 height,
bool migrates,
long numbelieve):
net2k(acolor,height),
bird(acolor,migrates),
itsnumberbelievers(numbelieve)
{
cout<<"派生类的打印输出.../n";
}
int main()
{
pegasus *ppeg=new pegasus(red,5,true,10); //false
ppeg->fly();
puts("");
ppeg->windows();
cout<<"/nppeg->getheight()的输出:"<<ppeg->getheight();
cout<<"NET2K1 tall and";
//判断部分
if(ppeg->getmigration())
cout<<"/n真D^_^.";
else
cout<<"/n假D!.";
cout<<"/nppeg->getnumberbelievers()的输出:"<<ppeg->getnumberbelievers();
delete ppeg;
return 0;
}