3

可能的重复:
C++ 相当于“超级”?

是否可以在不知道基类名称的情况下在子类中调用基类成员函数?(类似于在 java 中使用 super 关键字)

4

1 回答 1

1

C++ 没有super关键字的标准等效项。__super但是,如果您使用的是 Visual Studio,我认为有一个特定于微软的软件可以实现相同的效果。

// deriv_super.cpp
// compile with: /c
struct B1 {
   void mf(int) {}
};

struct B2 {
   void mf(short) {}

   void mf(char) {}
};

struct D : B1, B2 {
   void mf(short) {
      __super::mf(1);   // Calls B1::mf(int)
      __super::mf('s');   // Calls B2::mf(char)
   }
};

参考:msdn

于 2012-07-11T04:33:54.067 回答