由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - why use static function here?
相关主题
operator overloading (C++)tempalte as the overloaded conversion operator
请问关于overloading <<An object of A automatically converted to an object of B.
why copy assignment operator returns non-const type?C++ operator = overloading用copy & swap有啥优点
问个overloading new operator的问题one question about overloading operator delete
question overloading ++ error这段code有啥问题?
[C++] 入门级问题 increment and decrement operatorsHow to overload global new operator?
这两种容器定义形式有区别吗?问题的根源找到了
为什么在overloading中,friend <<不能读取private值呢?Go不支持operator overload
相关话题的讨论汇总
话题: operator话题: widget话题: static话题: function话题: const
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
Go不支持operator overloadquestion overloading ++ error
C++ function template问题[C++] 入门级问题 increment and decrement operators
operator() overloading 一问这两种容器定义形式有区别吗?
为啥gcc找不到类的构造函数?为什么在overloading中,friend <<不能读取private值呢?
operator overloading (C++)tempalte as the overloaded conversion operator
请问关于overloading <<An object of A automatically converted to an object of B.
why copy assignment operator returns non-const type?C++ operator = overloading用copy & swap有啥优点
问个overloading new operator的问题one question about overloading operator delete
相关话题的讨论汇总
话题: operator话题: widget话题: static话题: function话题: const