无法超载的运营商 - 为什么? [英] Operators that cannot be Overloaded - WHY?

查看:65
本文介绍了无法超载的运营商 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

唯一不能超载的运营商

是::(范围分辨率),. (成员选择),和。*(成员

通过指向函数的选择)。引自Stroustrup的第3版
这三个运算符''取一个名字,而不是一个值,作为他们的第二个操作数,并提供了引用成员的主要方式。

允许它们超载会导致细微之处。''"


首先,我见过?:和sizeof添加到此列表中。有人还提到''删除''b
但是Stroustrup并没有把它称为一个。事实上,

它位于可重载运算符列表中。


其次,'取名'是什么意思? 细微之处是什么意思?

关于这些背后的详细推理的任何想法?

解决方案

" ; Brad Eck <峰; br ****** @ sitesdynamic.com>写道...

"唯一不能超载的运营商是::(范围解析),. (成员选择),和。*(成员通过指向函数的选择)。引自Stroustrup的第3版这三个运算符''取名而不是值,作为他们的第二个操作数并提供引用成员的主要方式。
允许它们过载会导致细微之处。'''"

首先,我见过?:和sizeof添加到这个清单。


三元运算被排除在外可能是由于其关系的复杂性

。至于sizeof,::,他们真的不是真正意义上的运营商

,我想。

有人还提到''删除''但是Stroustrup并没有把它称为一个。实际上,它位于可重载运算符列表中。


''删除''可以重载。无论谁提到它可能都不知道他/她在说什么。

其次,'取名'是什么意思?什么是''微妙''的意思?


好​​吧,如果你超负荷了。 (会员访问)然后访问

成员的唯一方法是(& obj) - >成员。尴尬。现在,如果''&''和 - >

重载了,你得到了什么?...

对这些背后的详细推理有什么想法吗?




详细,''没有。尝试C ++的设计和演变。

a关于重载的全章。


V




Brad Eck <峰; br ****** @ sitesdynamic.com>在消息中写道

新闻:5e ************************* @ posting.google.co m ... < blockquote class =post_quotes>"唯一不能超载的运算符是::(范围分辨率),. (成员选择),和。*(成员通过指向函数的选择)。引自Stroustrup的第3版这三个运算符''取名而不是值,作为他们的第二个操作数并提供引用成员的主要方式。
允许它们过载会导致细微之处。'''"

首先,我见过?:和sizeof添加到这个清单。有人还提到''删除''但是Stroustrup并没有把它称为一个。事实上,
它位于可重载运算符列表中。

其次,取名是什么意思? 细微之处是什么意思?
关于这些背后的详细推理的任何想法?




大多数普通算子取值,例如operator +可能会添加两个整数

值。但是运营商的右手边。 。*和::是

的名称,例如类成员的名称。 ::的左手边也是一个名字。

名字和价值之间的差异对我来说似乎很清楚,我想

微妙之处就是事实在C ++中没有其他任何地方你允许

操纵类成员,变量等的名称。


john


Victor Bazarov写道:

''delete''可以重载。无论谁提到它可能都不知道他/她在谈论什么。




删除无法加载。这只是语法愚蠢,使得

释放函数称为operator delete。


"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup''s 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators ''take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.''"

First, I''ve seen ?: and sizeof added to this list. Someone also
mentioned ''delete'' but Stroustrup doesn''t refer to it as one. In fact,
it''s in the list of overloadable operators.

Second, what is meant by ''take a name''? What is meant by ''subtleties''?
Any thoughts as to the detailed reasoning behind these?

解决方案

"Brad Eck" <br******@sitesdynamic.com> wrote...

"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup''s 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators ''take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.''"

First, I''ve seen ?: and sizeof added to this list.
The ternary op is excluded probably due to complexity of its relation
to the assignment op. As to sizeof, ::, they''re not really operators
in the true sense, I guess.
Someone also
mentioned ''delete'' but Stroustrup doesn''t refer to it as one. In fact,
it''s in the list of overloadable operators.
''delete'' can be overloaded. Whoever mentioned it probably didn''t know
what he/she was talking about.
Second, what is meant by ''take a name''? What is meant by ''subtleties''?
Well, if you overload the . (member access) then the only way to access
a member would be (&obj)->member. Awkward. Now, if both ''&'' and -> are
overloaded, what do you get?...
Any thoughts as to the detailed reasoning behind these?



Detailed, ''fraid not. Try "Design and Evolution of C++". There is
a whole chapter on overloading.

V



"Brad Eck" <br******@sitesdynamic.com> wrote in message
news:5e*************************@posting.google.co m...

"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup''s 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators ''take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.''"

First, I''ve seen ?: and sizeof added to this list. Someone also
mentioned ''delete'' but Stroustrup doesn''t refer to it as one. In fact,
it''s in the list of overloadable operators.

Second, what is meant by ''take a name''? What is meant by ''subtleties''?
Any thoughts as to the detailed reasoning behind these?



Most normal operator take values, e.g. operator+ might add two integer
values. But the right hand side of operators . .* and :: are names of
things, e.g. name of a class member. Left hand side of :: is a name as well.
Difference between a name and a value seems pretty clear to me, and I guess
the subtleties would be the fact that nowhere else in C++ are you allow to
manipulate the names of class members, variables etc.

john


Victor Bazarov wrote:

''delete'' can be overloaded. Whoever mentioned it probably didn''t know
what he/she was talking about.



Delete CANNOT be loaded. It''s just syntactic stupidity that makes the
deallocation function called "operator delete".


这篇关于无法超载的运营商 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆