拜托,也许,我太累了,因为我似乎无法弄清楚为什么这个输入流运算符重载函数会抱怨......这是.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&)