c++ 继承多个类 及虚函数
#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;
}