C++进阶---菱形继承

V型继承

/*
V型继承
*/

#if 0

class Chair
{
private:
	int value;
public:
	Chair(int x = 0) :value(x) {}
	~Chair() {}
	void fun()
	{
		cout << "Chair" << endl;
	}
};

class Bed
{
private:
	int num;
public:
	Bed(int x = 0) :num{ x } {}
	~Bed() {}
	void fun()
	{
		cout << "Bed" << endl;
	}

};

class DeckChair :virtual public Bed, virtual public Chair
{
private:
	int sum;
public:
	DeckChair(int x = 0) :Chair{ x }, Bed{ x + 1 }, sum{ x + 2 } {}
	~DeckChair() {}
};


int main()
{
	DeckChair dr{ 10 };

	Chair* cp = &dr;
	Bed* bp = &dr;
	cp->fun();
	bp->fun();
	return 0;
}

#endif

 C++进阶---菱形继承_第1张图片

菱形继承

class Person
{
private:
	int 

你可能感兴趣的:(C++,c++,java,蓝桥杯)