c++ 继承多个类 及虚函数

时间:2023-01-27 17:11:20
#include <iostream>
using namespace std; class BaseA {
public:
    virtual void say() {
        cout << "hello world" << endl;
    }
}; class BaseB {
public:
    virtual void eat() {
        cout << " eating watermelon" << endl;
    }
}; class Human : public BaseA, public BaseB {
public:
    void dance(){
        cout << " dancing " << endl;
    }
}; int main(){
    Human man;
    man.eat();
    man.say();
    man.dance();     return 0;
} aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPMAAAA9CAIAAAD3dsisAAAEN0lEQVR4nO2dUbarIAxFOy4HxFqdDUPoKJiMg+n70CrQnEisvovx7J+7LmpEPCKFxDxer9fz+XyUDHF8z6TwOJiQ3jniCYY4vsc4HHre9aJ+tJy1TkPzDHE8oREP4ox27gVR2YRcHiqb+ITKJj6hsolPqGzikz9S9jS/0O2cwf/g1Akocq6y8aRSX8r+y8mvkPppB1f8kbL7gsp2iEnZ6yJLqYNs8WW+SflqRnUMeAtPKxqLpfwEtTEsQkGieZGpnuh656WXz7Z5S0hL7VOYrG7YybZVyhaXgpT2IRLtys5vQUhr2w5xXJo/L3/ofWF9Rws15HayHbf71m+dLGuA1noq17tKazkypKnsM8xaTSI7Wjt8CrJ/YPsQmWZlh9Si2ba95j2FPvvbTrHf5lL1ssNyWFmj9nrCPQrpLef5/P3smEtePVPVDvUVLptR+xBAq7KF13bViYEX96/KtvXZnwNDGlMaU8jNmuqJr1d+upCylXYT2wE2C5VtxKJssS3LF+PxfXbpQbX5W2syM8QUh5CmUcE6KDDUU5/WsSlb1eCGstln76V5NFK+hFfqIXHR4sp40DAaMd3DkN4pxjQPBFJKs1VrPdH1GpWN7VQH5v9L43Iq24hlbqR8swqDkTHGusWzHnf9zSW9neGda58ZWXfPxuh766ler0HZyA5qB1AXKttK76vr9ducswKkjd6VLczPcWGDNNC7stticAip6V/ZhOyByiY+obKJT6hs4hMqm/jkS9nm72Og2JDeYkZa6nMVh3Kyze/KnkEe9L151qv1obL9QGXnUNl+AMpeXt3FfTbG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