avatar
why use static function here?# Programming - 葵花宝典
g*n
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?
avatar
a*e
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?

avatar
X*r
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 @, [email protected] can be
interpreted as either [email protected](y) or [email protected](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?

avatar
g*n
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 @, [email protected] can be
: interpreted as either [email protected](y) or [email protected](x,y). If both forms
: of the operator function have been declared, the rul

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。