51.VC(Custom)-__super简介

来源:互联网 发布:airpak软件下载 编辑:程序博客网 时间:2024/06/16 11:31

http://msdn.microsoft.com/zh-cn/library/94dw1w7x.aspx
__super允许您显式说明要为正在重写的函数调用基类实现。如

__super::member_function();

备注
在重载决策阶段将考虑所有可访问的基类方法,可提供最佳匹配项的函数就是调用的函数。

  1. __super 只能在成员函数体内显示。
  2. __super 不能与声明一起使用。 有关更多信息,请参见using 声明。

在引入插入代码的特性后,您的代码可能包含一个或多个基类,您不知道该基类的名称,但其包含您希望调用的方法。
示例:

// deriv_super.cpp// compile with: /cstruct 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)   }};
1 0
原创粉丝点击