ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#include <iostream> #include <assert.h> using namespace std; class A{ public: int a; A(){ a1 = 1; a2 = 2; a3 = 3; a = 4; } void fun(){ cout << a1 << endl; cout << a2 << endl; cout << a3 << endl; cout << a << endl; } public: int a1; protected: int a2; private: int a3; }; class B: public A{ public: int a; B(int i){ A(); a = i; } void fun(){ cout << a << endl; cout << a1 << endl; cout << a2 << endl; // cout << a3 << endl; } }; int main(){ B b(10); cout << b.a << endl; cout << b.a1 << endl; // cout << b.a2 << endl; // cout << b.a3 << endl; } #include <iostream> #include <assert.h> using namespace std; class A{ public: int a; A(){ a1 = 1; a2 = 2; a3 = 3; a = 4; } void fun(){ cout << a1 << endl; cout << a2 << endl; cout << a3 << endl; cout << a << endl; } public: int a1; protected: int a2; private: int a3; }; class B: protected A{ public: int a; B(int i){ A(); a = i; } void fun(){ cout << a << endl; cout << a1 << endl; cout << a2 << endl; // cout << a3 << endl; } }; int main(){ B b(10); cout << b.a << endl; // cout << b.a1 << endl; // cout << b.a2 << endl; // cout << b.a3 << endl; } #include <iostream> #include <assert.h> using namespace std; class A{ public: int a; A(){ a1 = 1; a2 = 2; a3 = 3; a = 4; } void fun(){ cout << a1 << endl; cout << a2 << endl; cout << a3 << endl; cout << a << endl; } public: int a1; protected: int a2; private: int a3; }; class B: private A{ public: int a; B(int i){ A(); a = i; } void fun(){ cout << a << endl; cout << a1 << endl; cout << a2 << endl; // cout << a3 << endl; } }; int main(){ B b(10); cout << b.a << endl; // cout << b.a1 << endl; // cout << b.a2 << endl; // cout << b.a3 << endl; } #include <iostream> #include <assert.h> using namespace std; class A{ public: int a; A(){ a1 = 1; a2 = 2; a3 = 3; a = 4; } void fun(){ cout << a1 << endl; cout << a2 << endl; cout << a3 << endl; cout << a << endl; } public: int a1; protected: int a2; private: int a3; }; class B: public A{ public: int c; B(int i){ A(); c = i; } void fun(){ cout << a << endl; cout << a1 << endl; cout << a2 << endl; // cout << a3 << endl; } }; int main(){ B b(10); b.fun(); cout << b.a << endl; cout << b.c << endl; // cout << b.a1 << endl; // cout << b.a2 << endl; // cout << b.a3 << endl; } 4 1 2 4 10