Declaration Matching


Examples

The following example demonstrates that a derived class forms a different scope; hence, that a base class method whose name matches a method in the derived class is hidden rather than overloaded.

class base
{
 public:
  void f(int); // method is base::f
};
 
class derived : public base
{
 public:
  void f(int); // method is derived::f
               // the derived f hides but does not overload base::f
               // because derived method is declared in a different scope
};

The next example demonstrates how a function declared locally is in a different scope to a globally declared function.

void f(int);           // globally declared f.
 
void g()
{
 extern void f(char*); // hides the global function: void f(int);
 f(10);                // error ! void f(int); hidden in local scope
}