__super

来源:互联网 发布:网站流量统计软件 编辑:程序博客网 时间:2024/05/23 16:50
__super::member_function();
        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.
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)   }};int main() {}

这样子成员函数可以调用父的成员函数而不需要写父类名称,这是vs编译器特有的,gcc是不支持的。


1 0
原创粉丝点击