shadowing of functions in namespaces

Viewed 960

Suppose you have the following code

namespace a{
  struct S{};
  //void f(int){}
}

namespace b{
  struct T{};
}


struct X{};

void f(X){}
void f(b::T){}
void f(a::S){}



namespace a{
  void g(){

    S s;b::T t; 
    X x;
    f(x);
    f(s);
    f(t);
  }

}

int main(){
  a::g();
}

if void f(int){} is defined in namespace a (line 3 is uncommented), it shadows the later definitions of void f(b::T){} and void f(a::S){}, but not void f(X){}. Why?

1 Answers
Related