C++ 多继承 即:继承多个父类

#include 
using namespace std;

class Base1 {
public:
    Base1() {
        b1 = 1;
    }
    int b1;
protected:
private:
};

class Base2 {
public:
    Base2() {
        b2 = 2;
    }
    int b2;
protected:
private:
};

class Child : public Base1, public Base2 {
public:
    Child() {
        cout << "多继承-子类" << endl;
    }
    void printB() {
        cout << "b1: " << b1 << " b2: " << b2 << endl;
    }
protected:
private:
};

void main() {

    Child c1;
    c1.printB();
    system("pause");
}

你可能感兴趣的:(C和C++,c++,开发语言,算法)