from temp.local :
In the definition of a member of a class template that appears outside of the class template definition, the name of a member of the class template hides the name of a template-parameter of any enclosing class templates (but not a template-parameter of the member if the member is a class or function template). [ Example:
template<class T> struct A { struct B { /* ... */ }; typedef void C; void f(); template<class U> void g(U); }; template<class B> void A<B>::f() { B b; // A's B, not the template parameter } template<class B> template<class C> void A<B>::g(C) { B b; // A's B, not the template parameter C c; // the template parameter C, not A's C }
— end example ]
the problem is that, each compiler, that i have tried ( g++, vc, icc, clang ), treats C in A<B>::g(C)
as A's member name and doesn't compile that example.
Is this a common bug.?
template<class B> template<class C> void A<B>::g(C)
is the body definition for method member ofstruct A
. So, you better not try to make the compiler/developer confuse. In that case, the name of parameter still be hidden. Example, you can call:struct A<int> a; a.g<char>(1);
– Unmeet