Friday, November 5, 2010

Function Hiding

Given the following program:

  #include <iostream>
  using namespace std;
  namespace Out
  {
    void func(int i)
    {
      cout << "Out::func(int i)" << endl;
    }
    namespace In
    {
      void func(double d)
      {
        cout << "Out::In::func(double d)" << endl;
      }
      void dispatcher()
      {
       func(1);
      }
    }
  } // end namespaces Out::In
  using namespace Out;
  using namespace Out::In;
       
  int main() {
    dispatcher();
    return 0;
  }


"Out::In::func(double d)" is printed out.

This is the case where func(double d) hides func(int i).

No comments:

Post a Comment