#include <string>
#include <iostream>

using namespace std;

namespace
{
    class Animal
    {
    public:
        string GetInfo()
        {
            return "我是动物";
        }
    };

    class Dog :public Animal
    {
    public:
        using Animal::GetInfo;
        string GetInfo(string exta)
        {
            return "我是动物:" + exta;
        }
    };
}
#if 1

int main()
{
    Dog dog;
    //cout << dog.Animal::GetInfo() << endl;
    cout << dog.GetInfo() << endl;
    cout << dog.GetInfo("狗") << endl;

    return 0;
}

#endif
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.

输出:

我是动物
我是动物:狗
  • 1.
  • 2.

如果不是使用using语句声明,就需要用显式的域来访问:dog.Animal::GetInfo()