C++类访问控制

2020-05-06  本文已影响0人  FakeCSer爱去网吧
#include <iostream>
using namespace std;
class X
{
public:
    X(int A):a(A){}
    int a;//public member data:use object to access directly
};
class Y : public X
{
public:
    Y(int A,int B):X(A),b(B){}
    int showB(){return b;}
private:
    int b;//private member data:use showB to access
};
int main()
{
    X x(1);
    Y y(1,2);
    cout << x.a<<endl;
    cout << y.a<<y.showB()<<endl;
}

上一篇 下一篇

猜你喜欢

热点阅读