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,和参数是否相同,基类中的函数一律不再可见。

  • 相关阅读:
    华为P20 无法投屏到电视
    configuration error &ndash; unknown item &lsquo;umask&rsquo; (notify administrator)
    oracle不支持update from的语法
    SQL Server 中update的小计
    sqlplus连接oracle数据库--密码含特殊字符
    redhat 7.6安装oracle 11gR2遇到两个问题
    ORA-15032 ORA-15028
    ORA-07391 sftopen error unable to open text file
    ORA-01017 invalid username/password logon denied
    Oracle CRS/GI 进程介绍
  • 原文地址:https://www.cnblogs.com/dracohan/p/3813613.html
Copyright © 2011-2022 走看看