在学习别人的代码时,发现了一个__super,第一感觉很像java中的super,或者C#中的base网上查了一下发现作用差不多,都是指父类。C++本身没有__super,这是visual c++的扩展。其实在c++中,要使用父类的成员,可以直接用”父类名::成员”即可,或者利用using声明。

来自Microsoft的解释:

__super

Microsoft Specific

The __super keyword allows you to explicitly state that you are calling a base-class implementation for a function that you are overriding. All accessible base-class methods are considered during the overload resolution phase, and the function that provides the best match is the one that is called.

__super::member_function();

__super can only appear within the body of a member function.

With the introduction of attributes that inject code, your code might contain one or more base classes whose names you may not know but that contain methods that you wish to call.

Example

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

END Microsoft Specific

中文意思:

__super是编译器关键词,是一个辅助工具,在多重继承和多级继承环境下很方便,当你需要调用基类成员时,不需要你记忆这个成员到底是哪个基类提供的,编译器会帮你找到正确的基类。如果存在二义性(比如有两个基类提供了相同名称的成员),编译器会报错,在错误信息中会指出有哪些基类具有此成员,此时你可以根据提示信息把__super修改成希望的基类。总之一句话——它帮你减少记忆负担。

最新文章

  1. Windows 64位下装Oracle 11g,PLSQL Developer的配置问题,数据库处显示为空白的解决方案
  2. 【Alpha版本】冲刺-Day8
  3. 当html标签不被识别时(不解析)不妨试试htmlspecialchars_decode();试试
  4. JSBinding+SharpKit / 脚本加密(JSC或Bytecode,参考cocos2d-js)
  5. TCP与UDP协议
  6. RemoteWebDriver管理
  7. IOS打开其他应用、以及被其他应用打开
  8. 奥运会订票系统c语言代写源码下载
  9. 当 IDENTITY_INSERT 设置为 OFF 时,不能为表中的标识列插入显式值。
  10. Struts1.x 环境搭建和技术准备(上)
  11. win7(iis7)无法加载运行CSS和图片的解决方法
  12. RunLoop总结:RunLoop的应用场景(三)
  13. java 中拿项目路径
  14. mongodb基类封装实例
  15. C++学习笔记52:查找
  16. ionic this.navCtrl.push()和this.navCtrl.pop()
  17. PAT 乙级 1005 继续(3n+1)猜想 (25) C++版
  18. JVM总结-虚拟机加载类
  19. OpenMPI源码剖析:网络通信原理(二) 如何选择网络协议?
  20. 了不起的Node.js--之三

热门文章

  1. Qt程序Release版出现 类似 QEventLoop: Cannot be used without QApplication 问题的终极解决方案
  2. elixir 关键字列表
  3. 行动学习方法----PARR
  4. srop实战
  5. 重装系统,打开VS进行程序调试运行的时候 Unable to find manifest signing certificate in the certificate store
  6. iphone精简教程
  7. 【眼见为实】自己动手实践理解数据库READ UNCOMMITED && SERIALIZABLE
  8. [控件] LineAnimationView
  9. POST请求上传多张图片并携带参数
  10. 使用CAReplicatorLayer [1]