C++中的多重继承是指一个派生类可以同时继承多个基类的特性。在实现多重继承时,可以使用逗号分隔多个基类,如下所示:
class Base1 {
public:
void func1() {
cout << "Base1::func1()" << endl;
}
};
class Base2 {
public:
void func2() {
cout << "Base2::func2()" << endl;
}
};
class Derived : public Base1, public Base2 {
public:
void func3() {
cout << "Derived::func3()" << endl;
}
};
<< · Back Index ·>>
下一篇