第1版不正确:
myfunc(*this);
第二版很可能在该案中发挥作用,但我并不相信,如果涉及多重继承,它将在所有案件中发挥作用(正如你正在使用一种C-Style )。 我必须删除我的标准,看看C-Style的准确行为。
如果采用同一技术,如果你改用参考书,该方法就会发挥作用。
Update:
现在,我读过标准一,C-Cast将做正确的事(作为静态的预测和预测;并且可以用来从儿童到父母的等级等级划分)。
5.4 Explicit type conversion (cast notation)
4 The conversions performed by
— a const_cast (5.2.11),
— a static_cast (5.2.9),
— a static_cast followed by a const_cast,
— a reinterpret_cast (5.2.10), or
— a reinterpret_cast followed by a const_cast,
可以通过投放明确类型转换的标签来实现。 同样的语种限制和同种异构体也适用,但以下情况下在静态播种时,即使基类无法进入,转换也是有效的:
— a pointer to an object of derived class type or an lvalue or rvalue of derived class type may be explicitly converted to a pointer or reference to an unambiguous base class type, respectively;
— a pointer to member of derived class type may be explicitly converted to a pointer to member of an unambiguous non-virtual base class type;
— a pointer to an object of an unambiguous non-virtual base class type, a glvalue of an unambiguous non-virtual base class type, or a pointer to member of an unambiguous non-virtual base class type may be explicitly converted to a pointer, a reference, or a pointer to member of a derived class type, respectively.
如果能够以上述不止一种方式解释转换,则使用清单中首先出现的解释,即使由于这种解释而产生的解释不知情。 如果转换可以不止一种方式解释为静态预测,然后是星体预测,转换就不知情。