C++ 有 super() 方法没?

来源:互联网 发布:飞豆打印软件 连打 编辑:程序博客网 时间:2024/04/30 18:13

C++ 有 super() 方法没?

显然没有。为什么?

因为C++ 支持 多重继承,所以super()无法获得究竟是哪一个父类的同名方法。

那么该如何做呢?

只能用 父类名::方法名 这样来调用了。

Example:

#include <iostream>using namespace std;class Base{public:void f(){cout << "Base::f" << endl;}};class Derived : public Base{public:void f(){cout << "Derived::f" << endl;Base::f();}};int main(){Derived d;d.f();d.Base::f();return 0;}/*Derived::fBase::fBase::fPress any key to continue*/

0 0
原创粉丝点击