zoukankan      html  css  js  c++  java
  • C++-继承名称的掩盖

    ///////////////////////////////////////////////////////////////////////////////
    //
    //  FileName    :   effect_item33.h
    //  Version     :   0.10
    //  Author      :   Ryan Han
    //  Date        :   2013/07/26 16:50:14
    //  Comment     :  
    //
    ///////////////////////////////////////////////////////////////////////////////
    #ifndef EFFECT_ITEM33_H
    #define    EFFECT_ITEM33_H
    
    class base{
    public:
        virtual void mf1() = 0;
        virtual void mf1(int);
        virtual void mf2();
        void mf3();
        void mf3(double);
    private:
        int x;
    };
    
    class derive : public base {
    public:
        using base::mf1;
        void mf1();
        void mf4();
    private:
        int y;
    };
    
    #endif
    ///////////////////////////////////////////////////////////////////////////////
    //
    //  FileName    :   effect_item33.cpp
    //  Version     :   0.10
    //  Author      :   Ryan Han
    //  Date        :   2013/07/26 16:50:14
    //  Comment     :  
    //
    ///////////////////////////////////////////////////////////////////////////////
    #include "effect_item33.h"
    
    #include <iostream>
    using namespace std;
    
    void base::
    mf1() 
    {
        cout << "base::mf1() was called." << endl;
    }
    void base::
    mf1(int) 
    {
        cout << "base::mf1(int) was called." << endl;
    }
    void base::
    mf2() 
    {
        cout << "base::mf2() was called." << endl;
    }
    void base::
    mf3() 
    {
        cout << "base::mf3() was called." << endl;
    }
    void base::
    mf3(double) 
    {
        cout << "base::mf3(double) was called." << endl;
    }
    void derive::
    mf1() 
    {
        cout << "derive::mf1() was called." << endl;
    }
    void derive::
    mf4() 
    {
        cout << "derive::mf4() was called." << endl;
    }
    ///////////////////////////////////////////////////////////////////////////////
    //
    //  FileName    :   effect_item33_client.cpp
    //  Version     :   0.10
    //  Author      :   Ryan Han
    //  Date        :   2013/07/26 16:50:14
    //  Comment     :  
    //    Output        :
    //    $ ./a
    ///////////////////////////////////////////////////////////////////////////////
    #include "effect_item33.h"
    #include <iostream>
    using namespace std;
    
    int main() {
        derive d;
        d.mf1();
        d.mf1(3);
        return 0;
    }

    继承类中的成员函数将覆盖基类中的同名函数,不论virutal不virtual,和参数是否相同,基类中的函数一律不再可见。

  • 相关阅读:
    asp.net2.0 Theme and Skin
    Microsoft Exchange Server 2010 介绍
    Visual Studio 2010 Team System 动手实验室
    WCF中的消息契约
    Windows Workflow Foundation实验01——Windows Workflow Foundation 快速入门(练习二)
    C#中Brush、Color、String相互转换
    VS自动生成有参构造函数并自动依赖注入插件
    C#集合已修改:可能无法执行枚举操作
    Docker安装后启动不了,报“参考的对象类型不支持尝试的操作”
    windows下安装Docker超全图文教程
  • 原文地址:https://www.cnblogs.com/dracohan/p/3813613.html
Copyright © 2011-2022 走看看