请,也许吧,我太累了,因为我似乎无法弄清楚为什么这个输入流运算符重载的函数会抱怨..这是.h声明:
friend std::istream& operator>>(std::istream& in, IntOperatorClass& intoperatorClass)
这是.cpp声明:
std::istream& operator >>(std::istream& in, IntOperatorClass& intoperatorClass)
{
in>>intoperatorClass.value;
return in;
}
该类具有一个称为value的私有变量。
班级 :
class IntOperatorClass{
int value; //a value
int arr[10];//an array value
public:
IntOperatorClass();//default constructor
IntOperatorClass(int);//constructor with parameter
IntOperatorClass(int arr[], int length);//an array constructor
IntOperatorClass(const IntOperatorClass& intoperatorClass);//copy constructor
IntOperatorClass& operator=(const IntOperatorClass& intoperatorClass);//assignment operator
friend std::ostream& operator <<(std::ostream& out, const IntOperatorClass& intoperatorClass);//output operator;
friend std::istream& operator>>(std::istream& in, IntOperatorClass& intoperatorClass);//input operator
IntOperatorClass& operator++();//pre increment operator
IntOperatorClass operator++(int);//post increment operator
friend IntOperatorClass operator+(const IntOperatorClass intoperatorClassFirst , const IntOperatorClass intoperatorClassSecond);
int GetValue(){return value;}
};
我在做错什么吗,因为编译器一直抱怨“ >>”没有定义。
./op.cpp: In function 'std::istream& operator>>(std::istream&, IntOperatorClass&)':
../op.cpp:77: error: no match for 'operator>>' in 'in >> intoperatorClass->IntOperatorClass::value'
../op.cpp:75: note: candidates are: std::istream& operator>>(std::istream&, IntOperatorClass&)
最佳答案
不要忘记包含适当的标题:
#include <istream>
大概您包含一些标头,该标头以某种方式包含
std::istream
,但没有提取<istream>
标头的全部内容。