---
# System prepended metadata

title: 繼承

---

# 繼承
```
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

class bird
{
	public:
		void fly();
		void eat();
};

class crow:virtual public bird{
	public:
		void fly(){cout<<"crow fly"<<endl;		};
		void eat(){cout<<"crow eat"<<endl;		};
};

class pigeon:virtual public bird{ 
	public:
		void fly(){cout<<"pigeon fly"<<endl;		};
		void eat(){cout<<"pigeon eat"<<endl;		};
};

class sparrow:virtual public bird{
	public:
		void fly(){cout<<"sparrow fly"<<endl;		};
		void eat(){cout<<"sparrow eat"<<endl;		};
};

class penguin:virtual public bird{
	public:
		void fly(){cout<<"penguin fly"<<endl;		};
		void eat(){cout<<"penguin eat"<<endl;		};
		
		void swim(){cout<<"penguin swim"<<endl;		}
};

class chicken:virtual public bird{
	public:
		void fly(){cout<<"chicken fly"<<endl;		};
		void eat(){cout<<"chicken eat"<<endl;		};
		
		void speak(){cout<<"chicken speak"<<endl;		};
		
};

class duck:virtual public bird{
	public:
		void fly(){cout<<"penguin fly"<<endl;		};
		void eat(){cout<<"penguin eat"<<endl;		};
		
		void swim(){cout<<"penguin swim"<<endl;		}
};

int main()
{
	crow a;
	a.fly();
}
```