C++互为友元类,求大家来回答。

huangjunyu199115 2014-03-04 04:11:34
先不要管它干什么用,要怎样修改才可以运行呢?为什么要这样修改?

void set_input(){input=(input==TV)? DVD : TV;}
void settings() const;
void ch_h(Remote &t);
void input_ch_h(Remote &t);
private:
int state;
int volume;
int maxchannel;
int channel;
int mode;
int input;
};
class Remote
{
friend class Tv;
private:
int mode;
int style;

public:
enum{changgui,hudong};
Remote(int m=Tv::TV):mode(m){}
bool volup(Tv&t){return t.volup();}
bool voldown(Tv&t){return t.voldown();}
void onoff(Tv&t){t.onoff();}
void chanup(Tv&t){t.chanup();}
void chandown(Tv&t){t.chandown();}
void set_chan(Tv&t,int c){t.channel=c;}
void set_mode(Tv&t){t.set_mode();}
void set_input(Tv&t){t.set_input();}

};
inline void Tv::ch_h(Remote &t)
{
if(t.style==Remote::hudong)
t.style=Remote::changgui;
else t.style=Remote::hudong;
}
#endif

#include"151.h"
#include
bool Tv::volup()
{
if(volume {
volume++;
return true;
}
else
return false;
}
bool Tv::voldown()
{
if(volume>MinVal)
{
volume--;
return true;
}
else
return false;
}
void Tv::chanup()
{
if(channel channel++;
else
channel=1;
}
void Tv::chandown()
{
if(channel>1)
channel--;
else
channel=maxchannel;
}
void Tv::settings()const
{
std::cout<<"TV is "<<(state==Off? "Off":"On")<<std::endl;
if(state==On)
{
std::cout<<"Volume setting="<<volume<<std::endl;
std::cout<<"Channel setting="<<channel<<std::endl;
std::cout<<"Mode="<<(mode==Antenna? "antenna" : "cable")<<std::endl;
std::cout<<"Input="<<(input==TV? "TV":"DVD")<<std::endl;
}
}

#include
#include"151.h"
using namespace std;
bool Tv::volup()
{
if(volume {
volume++;
return true;
}
else
return false;
}
bool Tv::voldown()
{
if(volume>MinVal)
{
volume--;
return true;
}
else
return false;
}
void Tv::chanup()
{
if(channel channel++;
else
channel=1;
}
void Tv::chandown()
{
if(channel>1)
channel--;
else
channel=maxchannel;
}
void Tv::settings()const
{
cout<<"TV is "<<(state==Off? "Off":"On")<<endl;
if(state==On)
{
cout<<"Volume setting="<<volume<<endl;
cout<<"Channel setting="<<channel<<endl;
cout<<"Mode="<<(mode==Antenna? "antenna" : "cable")<<endl;
cout<<"Input="<<(input==TV? "TV":"DVD")<<endl;
}
}
...全文
131 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧