C++ 超载<&书信电报;运算符、分离实现和去宽容
我试图在类定义中重载,在操作符声明中添加关键字C++ 超载<&书信电报;运算符、分离实现和去宽容,c++,operator-overloading,C++,Operator Overloading,我试图在类定义中重载,在操作符声明中添加关键字friend friend ostream& operator << (ostream& output, const rollingDice& rd); 而不是 int temp=n; 在类定义中,将关键字friend添加到运算符声明中 friend ostream& operator << (ostream& output, const rollingDice& rd);
friend
friend ostream& operator << (ostream& output, const rollingDice& rd);
而不是
int temp=n;
在类定义中,将关键字
friend
添加到运算符声明中
friend ostream& operator << (ostream& output, const rollingDice& rd);
而不是
int temp=n;
这里描述了您的问题。您不需要运算符该问题在错误消息中解释:当编译器将运算符转换为函数调用时,它只给它一个参数。但是你已经用两个声明了。它需要处理调用它的对象。然后它说“必须正好接受两个参数”。这里描述了您的问题。您不需要运算符该问题在错误消息中解释:当编译器将运算符转换为函数调用时,它只给它一个参数。但是你已经用两个声明了。它需要处理调用它的对象。然后它说“必须正好接受两个参数”.friend也没有帮助。rollingDice.cpp:34:14:错误:“n”未在rollingDice包含的文件中的此作用域中声明。cpp:5:0:rollingDice.h:17:7:错误:“int*rollingDice::r”为private@AlpÖzgüder这些错误与您最初的问题没有任何共同之处。不过我会帮助你的。查看我的更新帖子。我还忘了在rollingDice之前在实现中添加“const”。现在它工作了!friend也没有帮助。rollingDice.cpp:34:14:错误:“n”未在rollingDice包含的文件中的此作用域中声明。cpp:5:0:rollingDice.h:17:7:错误:“int*rollingDice::r”为private@AlpÖzgüder这些错误与您最初的问题没有任何共同之处。不过我会帮助你的。查看我的更新帖子。我还忘了在rollingDice之前在实现中添加“const”。现在它工作了!
friend ostream& operator << (ostream& output, const rollingDice& rd);
int temp=rd.n;
int temp=n;