C++継承中の名前検索

958 ワード

#include<iostream>
#include<string>
using namespace std;
class Base {
 public:
  void func() {
    cout << "func() in Base." << endl;
  }
  void func(int a) {
    cout << "func(int a) in Base." << endl;
  }
  void func(string s) {
    cout << "func(string s) in Base." << endl;
  }
};


class Derived : public Base { 
public:
  //using Base::func;
  void print() {
    cout << "func() in Derived." << endl;
  }
};


int main() {
  Derived d;
  d.Base::func();//      
  d.func();
  d.func(12);//error,        using Base::print;
  d.func("abc");//error,        using Base::print;
  system("pause");
  return 0;
}
//    ,  ,                   。
//               
//               
//                      ,                ,        。
//  using                         
//          ,                ,         ,