# 繼承 ``` #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(); } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up