Shading functions in namespaces

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){}defined in the namespace a (line 3 uncommented), it obscures the later definitions of void f(b::T){}and void f(a::S){}, but not void f(X){}. Why?

+5
source share
1 answer

The shades of f(char)and f(int)will be called, since char can be implicitly cast in int. http://liveworkspace.org/code/8d7d4e0bc02fd44226921483a910a57b

EDIT.

A. f(int). f(A::S). f (s), s A::S g, A, , S (A::S), A , . http://liveworkspace.org/code/5f989559d2609e57c8b7a655d5b1cebe

f(B::T). A (f(int)) B ( arg-type B), , . http://liveworkspace.org/code/4ebb0374b88b29126f85038026f5e263

f(X), X , A (f(int)) (find f(X)) - . http://liveworkspace.org/code/c9ef24db2b5355c4484aa99884601a1a

3.4.2 ++ ( n3337). , http://en.wikipedia.org/wiki/Argument-dependent_name_lookup

+3

All Articles