c++-C++友元的问题。不知道错在哪里。弄得恼火了。。求助。

问题描述

C++友元的问题。不知道错在哪里。弄得恼火了。。求助。

先不要管它干什么用,要怎样修改才可以运行呢?为什么要这样修改?

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;
}
}

解决方案

代码贴的不完整,最好把完整代码贴出来,inline void Tv::ch_h(Remote &t),这个Tv类利用Remote类,这个你上前声明了Remote类么?

inline void Tv::ch_h(Remote &t)
{
if(t.style==Remote::hudong)
t.style=Remote::changgui;
else t.style=Remote::hudong;
}
Tv类是Remote类的友元类,但Remote类并不是Tv类的友元类,总之代码不完整,不好看

时间: 2024-08-31 09:11:52

c++-C++友元的问题。不知道错在哪里。弄得恼火了。。求助。的相关文章

html-这个验证跳转总是失败,实在不知道错在哪,可以帮我看看吗?

问题描述 这个验证跳转总是失败,实在不知道错在哪,可以帮我看看吗? 主页登陆<br> function check() {<br> if (document.forms(0).name.value == "123" && document.forms(0).pw.value == "123456") {<br> window.location = "body.html";<br> }

代码-我的JS实行不了跳转,不知道错在哪

问题描述 我的JS实行不了跳转,不知道错在哪 regist.php中的一行 <dd class=""face""><img src=""images/1.jpg"" alt=""头像选择"" id=""faceimg""/></dd> JS文件中的代码 window.onload=function(){ var

报错-我刚学Qt,能帮我改改代码吗?不知道错哪了

问题描述 我刚学Qt,能帮我改改代码吗?不知道错哪了 解决方案 第一个源代码缺少 include "mydilaog.h"

malloc-小弟谢了一个简单的字符串求最大子串的程序不知道错哪里,請大神帮忙回答下

问题描述 小弟谢了一个简单的字符串求最大子串的程序不知道错哪里,請大神帮忙回答下 程序要求如下: 一个字符串,字符连续的部分为子串(不含带数字的部分) 下面是我写的程序 #include using namespace std; char* BiggestStr(char* str) { char* pStr = (char*)malloc(sizeof(str)+1); //申请一个空间存最大子串 int nCount = 0; //用于记录最大子串的长度 int J_nCount=0; ch

自学string 发现了问题但是不知道错在哪里了

问题描述 自学string 发现了问题但是不知道错在哪里了 自学string 发现了问题但是不知道错在哪里了 #include #include #include #include using std:: string; using namespace std; int main() { string str("some string"); for( auto c:str) cout << c << endl; return 0; } 解决方案 你的编译器版本是

vs2012-我的C程序VS2013报错,都不知道错哪了,请大神指教

问题描述 我的C程序VS2013报错,都不知道错哪了,请大神指教 hash函数名和数组next都定义了,都不知道哪错了 解决方案 感觉是标准库的某些内容重复了. std::next是里的template, std::hash是里的template. 都是c++ 11定义的. 解决方案二: 自己重新定义一下名字,这几个名字已经在类库中存在了 解决方案三: 你的定义重复了,如果你的代码没有重复定义它们,可能是和你包含的库文件冲突了,那么换个名字看看 解决方案四: hash和next重复定义了. 你可

c++-求两个日期相差的天数 用友元函数 我不知道要怎么改 看不懂调试。

问题描述 求两个日期相差的天数 用友元函数 我不知道要怎么改 看不懂调试. #include class Date {int yearmonthday;public : void show(); int set(int aint bint c); friend int End(Date &d1 Date &d2);};void Date::show (){cout<<""please input year monthday.""<}

c语言 数据结构-用c写了一个舞伴配对,却不知道错在哪,求解

问题描述 用c写了一个舞伴配对,却不知道错在哪,求解 #include #include #include #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define MAXSIZE 100 typedef int Status; typedef struct { char name[20]; char sex; }Person,QElemType; typedef struct Qnode { QElemType data; struct

c-链队列不对 不知道错在哪里

问题描述 链队列不对 不知道错在哪里 #include#includetypedef struct Node { int number; char name[20]; Node *next;}Qnode;typedef struct { Qnode *front; Qnode *rear;}LinkQueue;void Enqueue(LinkQueue *q){ int n; scanf_s(""%d"" &n); for (int i = 1;i <