虚继承

#include<iostream>
using namespace std;

class GrandFather
{

public:
	void show()
	{
		cout<<"GrandFather show"<<endl;
		return;
	}

};
class Father:virtual public GrandFather
{
};
class Mother:virtual public GrandFather
{

};
class Son:public Father,public Mother
{
};

int main(int argc,char**argv)
{

	Son s;
	s.show();
	
	return 0;
}

//虚继承才有了虚基类,以防止二义性的出现




posted @ 2015-11-07 19:45  cloudren2020  阅读(82)  评论(0编辑  收藏  举报