<分区>
Possible Duplicate:
C++ equivalent of “super”?
是否可以在不知道基类名称的情况下在子类中调用基类成员函数? (类似于在 java 中使用 super 关键字)
<分区>
Possible Duplicate:
C++ equivalent of “super”?
是否可以在不知道基类名称的情况下在子类中调用基类成员函数? (类似于在 java 中使用 super 关键字)
最佳答案
C++ 没有标准的 super
关键字。但是有一个特定于 Microsoft 的 __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
关于c++ - 如何在不知道 C++ 基类名称的情况下调用子类中基类的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11425510/