虛函數(shù) 多態(tài)
出現(xiàn)菱形繼承蜜宪,上兩條表用虛擬繼承,其他兩條邊隨意
——————————————————————
#include<iostream>
using namespace std;
class person
{
public:
int id;
};
class father:virtual public person //
{
public:
father(){id=30;}
void money()
{
cout<<"money"<<endl;
}
};
class mother:virtual public person //
{
public:
mother(){id=20;}
void face()
{
cout<<"漂亮,高"<<endl;
}
};
class son:public mother,public father
{
};
int main()
{
son s;
s.id; //為什么打印的是后者的id放典?冈爹??
cout<<s.id<<endl;
}
——————————————————————————————————————