0
点赞
收藏
分享

微信扫一扫

基类的保护成员,在子类中直接访问的例程

秦瑟读书 2022-06-08 阅读 77

源程序:

#include<iostream>
using namespace std;class A
{
protected:
int x;
public:
A(int a)
{
x=a;
}
int get_x()
{
return x;
}
void show()
{
cout<<"x="<<x<<endl;
}
};
class B:public A
{
private:
int y;
public:
B(int b):A(b)
{
y=b;
}
void show()
{
cout<<"A::x="<<x<<endl;
}
};int main()
{
A m(10);
B n(20);
//cout<<m.x<<endl;
cout<<m.get_x()<<endl;
n.show();
return 1;
}
举报

相关推荐

nginx 禁止ip直接访问

0 条评论