博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VC++中的__super::
阅读量:4500 次
发布时间:2019-06-08

本文共 1327 字,大约阅读时间需要 4 分钟。

  在学习别人的代码时,发现了一个__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  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.cppstruct 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)   }};int main() {}

END Microsoft Specific

 

中文意思:

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

转载于:https://www.cnblogs.com/rainbow70626/p/8831125.html

你可能感兴趣的文章
java开发知识IO知识之输入输出流以及文件
查看>>
SurfaceViewVideoList网络获取视频播放
查看>>
Oracle 笔记(二)
查看>>
微信公众号开发--访问网络用到的工具类
查看>>
wpf中利用多重绑定实现表中数据越界自动报警
查看>>
为Linux配置常用源:epel和IUS
查看>>
天府地
查看>>
C#高级编程
查看>>
JS实现从照片中裁切自已的肖像
查看>>
使用 https://git.io 缩短 a GitHub.com URL.
查看>>
拷贝、浅拷贝、深拷贝解答
查看>>
NS3 实验脚本的编写步骤
查看>>
四元数
查看>>
【Linux】Linux查看程序端口占用情况
查看>>
微软职位内部推荐-Software Development Engineer
查看>>
Git常用命令
查看>>
Windows 2003+IIS6+PHP5.4.10配置PHP支持空间的方法(转)
查看>>
去除express.js 3.5中报connect.multipart() will be removed in connect 3.0的警告(转)
查看>>
Android WIFI 无缝切换 小结(1)
查看>>
BZOJ 5194--[Usaco2018 Feb]Snow Boots(STL)
查看>>