📄 ch17_2.cpp
字号:
//**********************
//** ch17_2.cpp **
//**********************
#include<iostream.h>
class Furniture{
public:
Furniture(){}
void SetWeight(int i){ weight =i; }
int GetWeight(){ return weight; }
protected:
int weight;
};
class Bed :public Furniture{
public:
Bed(){}
void Sleep(){ cout <<"Sleeping...\n"; }
};
class Sofa :public Furniture{
public:
Sofa(){}
void WatchTV(){ cout <<"Watching TV.\n"; }
};
class SleeperSofa :public Bed, public Sofa{
public:
SleeperSofa() :Sofa(), Bed(){}
void FoldOut(){ cout <<"Fold out the sofa.\n"; }
};
void main()
{
SleeperSofa ss;
ss.SetWeight(20); //编译出错!模糊的SetWeight成员
Furniture* pF;
pF =(Furniture*)&ss; //编译出错!模糊的Furniture*
cout <<pF->GetWeight() <<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -