无法超载的运营商

无法超载的运营商

本文介绍了无法超载的运营商 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 唯一不能超载的运营商 是::(范围分辨率),. (成员选择),和。*(成员 通过指向函数的选择)。引自Stroustrup的第3版 这三个运算符''取一个名字,而不是一个值,作为他们的第二个操作数,并提供了引用成员的主要方式。 允许它们超载会导致细微之处。''" 首先,我见过?:和sizeof添加到此列表中。有人还提到''删除''b 但是Stroustrup并没有把它称为一个。事实上, 它位于可重载运算符列表中。 其次,'取名'是什么意思? 细微之处是什么意思? 关于这些背后的详细推理的任何想法? 解决方案 详细,''没有。尝试C ++的设计和演变。 a关于重载的全章。 V 大多数普通算子取值,例如operator +可能会添加两个整数 值。但是运营商的右手边。 。*和::是 的名称,例如类成员的名称。 ::的左手边也是一个名字。 名字和价值之间的差异对我来说似乎很清楚,我想 微妙之处就是事实在C ++中没有其他任何地方你允许 操纵类成员,变量等的名称。 john 删除无法加载。这只是语法愚蠢,使得 释放函数称为operator delete。 "The only operators that cannot be overloadedare :: (scope resolution), . (member selection), and .* (memberselection through pointer to function). Quoting from Stroustrup''s 3rdedition of _The C++ Programming Language_, section 11.2 (page 263),these three operators ''take a name, rather than a value, as theirsecond 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 alsomentioned ''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? 解决方案Detailed, ''fraid not. Try "Design and Evolution of C++". There isa whole chapter on overloading.VMost normal operator take values, e.g. operator+ might add two integervalues. But the right hand side of operators . .* and :: are names ofthings, 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 guessthe subtleties would be the fact that nowhere else in C++ are you allow tomanipulate the names of class members, variables etc.johnDelete CANNOT be loaded. It''s just syntactic stupidity that makes thedeallocation function called "operator delete". 这篇关于无法超载的运营商 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 18:44