ch17_2.cpp
来自「本文档是(作者:钱能)《C++程序设计教程》系列的部分辅助代码。 选题编辑:张」· C++ 代码 · 共 42 行
CPP
42 行
//**********************
//** 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 + =
减小字号Ctrl + -
显示快捷键?