C++高级编程一书说,可以如下这样重载操作符,但是我编译的时候出错了。
friend const SpreadsheetCell& operator+(const SpreadsheetCell& rth, const SpreadsheetCell& lth);
const SpreadsheetCell SpreadsheetCell::operator +(const SpreadsheetCell& rhs, const SpreadsheetCell& lhs)
{
SpreadsheetCell newCell;
newCell.set(lhs.mValue + rhs.mValue);
return (newCell);
}
编译出错如下:
G:\qt\sheet-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK____\..\Sheet\SpreadsheetCell.cpp:45: 错误:'const SpreadsheetCell SpreadsheetCell::operator+(const SpreadsheetCell&, const SpreadsheetCell&)' must take either zero or one argument
说的大概就是只能有0个或者一个参数,不知道为什么。。