使用基类的所有重载

发布于 2024-08-07 05:56:24 字数 162 浏览 1 评论 0原文

当子类重写基类的方法时,子类无法使用基类的所有重载。为了使用它们,应该在子类中添加 using BaseClass::Method; 行。

有没有一种快速的方法来继承基类的所有重写方法的重载? (不需要为每个方法显式指定 using ...

When a subclass overrides a baseclass's method, all of the baseclass's overloads are not available from the subclass. In order to use them there should be added a using BaseClass::Method; line in the subclass.

Is there a quick way to inheirt the baseclass's overloads for ALL of the overridden methods? (not needing to explicitly specify using ... for each method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国际总奸 2024-08-14 05:56:24

不可以。这只能通过 using 声明实现,并且仅适用于各个方法。

No. It's only possible with a using declaration and that only works with the individual methods.

素罗衫 2024-08-14 05:56:24

当您想要调用方法时,您可以通过显式指定类的范围来访问基类的方法...

例如

class Base{
 public: void foo(){}
};

class Derived : public Base {
 public: void foo(int){}
};

int main()
{
    Derived d;
    *d.Base::foo();* // like this
}

You can access base class's method, by explicitly specifying scope of the class when you want to call method...

e.g

class Base{
 public: void foo(){}
};

class Derived : public Base {
 public: void foo(int){}
};

int main()
{
    Derived d;
    *d.Base::foo();* // like this
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文