隐藏

void MyBase::SetName(int i,int j)
{

     ostringstream ost;
     ost << i;
      name=ost.str();
    cout<<i<<"*"<<j<<"*2"<<endl;
}

 

void MySun::SetName(int i,int j)
{

     SetName(i,j);
     ostringstream ost;
     ost << i;
     name=ost.str();
    cout<<i<<"*"<<j<<"*2"<<endl;
}

 

这样是不行的! 因为有个东西叫隐藏!!!

 为了让隐藏再次可见,使用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;        // 让积累中所有名为 mf1 和 mf3 的东西

  using Base::mf3;        // 在 Derived 的作用域中可见(并且是公有的)

  virtual void mf1();

  void mf3();

  void mf4();

  ...

};

 其实 说白了就是: 使用 Base:: 来实现类似c#中的 base. 功能

posted on 2013-07-29 15:20  shoutcharter  阅读(103)  评论(0编辑  收藏  举报

导航