简体   繁体   English

何时以及为什么超类运算符重载隐藏在子类中?

[英]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.

相关问题 自定义 std::ostream 子类中的运算符 &lt;&lt; 重载的歧义错误 - Ambiguity Errors with operator<< Overloads in custom std::ostream Subclass 为什么赋值运算符重载中不需要get函数? - Why are no get functions needed in assignment operator overloads? 为什么 C# 运算符重载必须是静态的? - Why must C# operator overloads be static? 为什么受保护的超类成员在作为参数传递时无法在子类函数中访问? - Why protected superclass member cannot be accessed in a subclass function when passed as an argument? 为什么调用超类方法时子类变量不会改变c ++ - why doesn't subclass variable get changed when called superclass methods c++ 为什么cout在重载运算符&lt;&lt;的朋友函数中不起作用,这是istream运算符 - Why cout is not working in the friend function that overloads the operator << which is an istream operator 如何在抽象超类的子类中重载 operator+? - How do you overload operator+ in a subclass of an abstract superclass? 我在模板 class 中有多个 * 运算符重载。 当我将声明以不同的顺序放置时,为什么会得到不同的结果? - I have multiple overloads of the * operator in a template class. Why do I get different results when I put the declarations in different order? 为什么必须在运算符重载中提供关键字const - why must you provide the keyword const in operator overloads 为什么编译器可以找到这些运算符重载之一,却找不到另一个? - Why can the compiler find one of these operator overloads but not the other?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM