4-2.txt

来自「思路很清晰的c++课件。例子很简明」· 文本 代码 · 共 25 行

TXT
25
字号
#include <iostream.h>

class base{		//基类
	int x;
public:
	void setx(int n){x=n;}
	void showx(){cout<<x<<endl;}
};

class derived:private base{		//私有派生类
	int y;
public:
	void sety(int m){y=m;}
	void showy(){cout<<y<<endl;}
};

void main()
{
	derived obj;
	obj.setx(10);		//?
	obj.sety(20);		//ok
	obj.showx();		//?
	obj.showy();		//ok
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?