#include <iostream>
using namespace std;
class base1 {
protected:
int x;
public:
void showx() { cout << x << endl; }
};
class base2 {
protected:
int y;
public:
void showy() { cout << y << endl; }
};
//从多个类中继承
class derived: public base1, public base2 {
public:
void set (int i, int j) { x = i; y = j; }
};
int main()
{
derived ob;
ob.set(10, 20); //派生类中定义的函数
ob.showx(); //从 base1 中继承
ob.showy(); //从 base2 中继承
return 0;
}
$ ./mulinherit
10
20
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |