#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Animal {
	public:
		Animal(int age) :m_nage(age) 
		{
			cout << "animal constructor" << endl;
		}
protected:
	int m_nage;
};
class Bird :virtual public Animal{
public:
	Bird(int age, int fh):Animal(age)
	{
		cout << "bird constructor" << endl;
		m_nflightaltitude = fh;
	}
	int get_flightaltitude()
	{
		return m_nflightaltitude;
	}
private:
	int m_nflightaltitude;
};
class Fish :virtual public Animal {
	private:
		int m_nswimspeed;
public:
	Fish(int age, int speed) :Animal(age)
	{
		cout << "fishconstructor" << endl;
		m_nswimspeed = speed;
	}
	int get_swimspeed()
	{
		return m_nswimspeed;
	}
};
class Waterbird :public Bird, public Fish {
public:
	Waterbird(int b_age, int f_age, int fh, int speed) :Bird(b_age,fh), Fish(f_age, speed), Animal(b_age)
	{
		cout << "waterbird constructor" << endl;
	}
	void print_animalage()
	{
		cout << "age=" << m_nage << endl;
	}
};
int main()
{
	Waterbird waterbird(5, 6, 20, 30);
	cout << waterbird.get_flightaltitude() << ' ' << waterbird.get_swimspeed() << endl;
	waterbird.print_animalage();
	system("pause");
	return 0;
}

虚基类_C  编程