📄 4-3.txt
字号:
例4.3 公有派生
#include <iostream.h>
class base{ //基类
int x;
public:
void setx(int n){x=n;}
void showx(){cout<<x<<endl;}
};
class derived:public base{ //公有派生类
int y;
public:
void sety(int m){ y=m;}
void showy(){ cout<<y<<endl;}
};
void main()
{
derived obj;
obj.setx(10); //ok
obj.sety(20); //ok
obj.showx(); //ok
obj.showy(); //ok
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -