g*****n 发帖数: 56 | 1 from effective C++ (2nd ed) item 28
struct widgets{
class widget {....};
static const Widget operator+(const Widget& lsh, const Widget& rhs);
....
};
I am wondering why declare a overloaded operator static? | a***e 发帖数: 1140 | 2 I understand that, for the derivative classes. They have the common entrance
(address) for their functions.
But I admit I don't find any advantage for operator overload case.
【在 g*****n 的大作中提到】 : from effective C++ (2nd ed) item 28 : struct widgets{ : class widget {....}; : : static const Widget operator+(const Widget& lsh, const Widget& rhs); : .... : }; : I am wondering why declare a overloaded operator static?
| X****r 发帖数: 3557 | 3 I don't think you can overload operator + as a static member.
Quote:
13.5.2 Binary operators [over.binary]
1 A binary operator shall be implemented either by a non-static member
function (_class.mfct_) with one parameter or by a non-member function
with two parameters. Thus, for any binary operator @, x@y can be
interpreted as either x.operator@(y) or operator@(x,y). If both forms
of the operator function have been declared, the rul
【在 g*****n 的大作中提到】 : from effective C++ (2nd ed) item 28 : struct widgets{ : class widget {....}; : : static const Widget operator+(const Widget& lsh, const Widget& rhs); : .... : }; : I am wondering why declare a overloaded operator static?
| g*****n 发帖数: 56 | 4 but stott meyers's effective C++ use it. Maybe there is some subtle meaning, b
ut i can not figure out.
【在 X****r 的大作中提到】 : I don't think you can overload operator + as a static member. : Quote: : 13.5.2 Binary operators [over.binary] : 1 A binary operator shall be implemented either by a non-static member : function (_class.mfct_) with one parameter or by a non-member function : with two parameters. Thus, for any binary operator @, x@y can be : interpreted as either x.operator@(y) or operator@(x,y). If both forms : of the operator function have been declared, the rul
|
|