Overloads of inherited member functions

Deadly 提交于 2019-11-30 11:36:25
Ates Goral

You can do three things:

1. Unhide the base class method

Add a using in the Node declaration:

using Bound::rebound;
void rebound() { rebound(left, right); }

2. Explicitly refer to the base class method

Use the Bound namespace:

void rebound() { Bound::rebound(left, right); }

3. Define/redefine all overloads in the derived class

Delegate the implementation to the base class (if this is done in the header, there shouldn't be any penalty thanks to inlining):

void rebound(const Bound *a, const Bound *b) { Bound::rebound(a, b); };
void rebound() { rebound(left, right); }

More info: https://isocpp.org/wiki/faq/strange-inheritance#overload-derived

When you declare a method in the subclass with the same name but a different signature, it actually hides the version from the parent.

You could refer to it specifically as Bound::rebound(...) or use the using keyword.

See here

This is called hiding the parent member function. You can explicitly call it (by Bound::rebound(left, right) as @Ates Goral said) or you can add a using Bound::rebound in your Node class definition.

See http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9 for more info.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!