[英]When and why are superclass operator overloads hidden in a subclass?
I'm aware that if a subclass provides an operator method (let's say assignment), this hides that operator in the superclass unless you explicitly do using superclass::operator=
but in my code, I've seen cases I need to do this even when the sub-class does not implement any operators at all. 我知道如果子类提供了一个运算符方法(让我们说赋值),这会隐藏超类中的运算符,除非你明确地
using superclass::operator=
但是在我的代码中,我已经看到我需要这样做的情况即使子类根本没有实现任何运算符。
Is there a concrete list of cases where operators (and other moethds if it's a general case) will be hidden and where they won't? 是否有一个具体的案例清单,其中操作员(以及其他一些情况下的一般情况)将被隐藏,哪些不会被隐藏?
Related: Trouble with inheritance of operator= in C++ . 相关: 在C ++中继承operator =的麻烦 。
operator=
is the only member function (other than constructors and destructor) that's compiler-generated, and hence the only function that's hidden even when not user-declared in the derived class. operator=
是编译器生成的唯一成员函数(构造函数和析构函数除外),因此即使在派生类中未进行用户声明时,它也是唯一隐藏的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.