C++ 多继承之如何调用私有成员
#include <iostream>
using namespace std;
class A {
private:
int a;
public:
void setA(int a) {
this->a = a;
}
void showA() {
cout << "a = " << a << endl;
}
};
class B {
private:
int b;
public:
void setB(int b) {
this->b = b;
}
void showB() {
cout << "b = " << b << endl;
}
};
class C :public A, private B {
private:
int c;
public:
void setC(int a,int b) {
this->c = a;
setB(b);
}
void showC() {
showB();
cout << "c = " << c << endl;
}
};
int main() {
C objc;
objc.setA(53);
objc.showA();
objc.setC(55,58);
objc.showC();
}
以上就是多继承如何访问私有成员的脚本