OOP—还原被遮掩的继承名称

1。public继承——using 声明式

class Base
{
private:
    int x;
public:
    virtual void mf1() = 0;
    virtual void mf1(int) ;
    virtual void mf2();
    void mf3();
    void mf3(double);
    ...
};

class Derived: public Base
{
public:
    using Base::mf1;  //让Base Class内名为mf1和mf3的所有东西在Derived作用域内都可见(并且public)
    using Base::mf3;
    virtual void mf1();
    void mf3();
    void mf4();
    ...
};

 

2。private继承——转交函数

class Base
{
private:
    int x;
public:
    virtual void mf1() = 0;
    virtual void mf1(int) ;
    virtual void mf2();
    void mf3();
    void mf3(double);
    ...
};

class Derived: public Base
{
public:
    virtual void mf1()    //转交函数
   { Base::mf1(); }      //暗自成为inline
    void mf3();
    void mf4();
    ...
};

 

posted @ 2016-07-28 08:31  秋水小战士  阅读(141)  评论(0编辑  收藏  举报