template parameter hiding
A point from ISO draft n3290 section 3.3.9 paragraph 4:
The declarative region of the name of a template parameter is nested within the immediately-enclosing declarative region.[Note: As a result, a template-parameter hides any entity with the same name in an enclosing scope (3.3.10)开发者_如何学Python.
Example:
typedef int N;
template<N X, typename N, template<N Y> class T> struct A;
Can any one please ....tell some other example other than this ..where & where this situation erises
draft link n3290: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3290.pdf
I think it is quite obvious: any time that an entity in the scope of the template declaration has the same name as one of the template parameters, the name will be hidden within the template. If you are having problems coming up with examples chances are that you did not understand the meaning of the quote. What is it that you understood? What is it that you have troubles understanding?
Also for those that don't want to go into the standard, it is important to complete the original quote:
typedef int N;
template<N X, typename N, template<N Y> class T> struct A;
Here, X is a non-type template parameter of type int and Y is a non-type template parameter of the same type as the second template parameter of A. -- end example ] -- end note ]
Which helps understanding the example. Note what the quote means: the first N
refers to the typedef
at the namespace scope, then a template argument N
is introduced. From there on, the template argument hides the outer N
, and the next appearance of N
refers to the template argument and not to the outer N
(only within the declarative scope of the template)
Sure:
int n = 0;
void f() {
int n = 42;
}
The n in the function hides the one declared at global scope.
精彩评论