重载<<操作符错误C2804:二进制'运算符<<参数太多 [英] Overloading the << operator error C2804: binary 'operator <<' has too many parameters
本文介绍了重载<<操作符错误C2804:二进制'运算符<<参数太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的类:
#ifndef CLOCK_H
#define CLOCK_H
using namespace std;
class Clock
{
//Member Variables
private: int hours, minutes;
void fixTime( );
public:
//Getter & settor methods.
void setHours(int hrs);
int getHours() const;
void setMinutes(int mins);
int getMinutes() const;
//Constructors
Clock();
Clock(int);
Clock(int, int);
//Copy Constructor
Clock(const Clock &obj);
//Overloaded operator functions
void operator+(const Clock &hours);
void operator+(int mins);
void operator-(const Clock &hours);
void operator-(int minutes1);
ostream &operator<<(ostream &out, Clock &clockObj); //This however is my problem where i get the error C2804. Saying that it has to many parameters
};
#endif
这个函数应该是一个时钟的值不同时间。
All this function is supposed to do is out the values of a clock at different times.
推荐答案
ostream &operator<<(ostream &out, Clock &clockObj);
应为
friend ostream &operator<<(ostream& out, Clock &clockObj);
定义在类外。
这篇关于重载<<操作符错误C2804:二进制'运算符<<参数太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文