模板参数隐藏
ISO 草案 n3290 第 3.3.9 节第 4 段中的一点:
模板参数名称的声明区域嵌套在 立即封闭声明式 区域。[注:结果, 模板参数隐藏任何实体 在附件中具有相同的名称 范围(3.3.10)。
Example:
typedef int N;
template<N X, typename N, template<N Y> class T> struct A;
任何人都可以....告诉一些除此之外的其他例子..where &出现这种情况的地方
草案链接 n3290: http:// /www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3290.pdf
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).
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是非常明显的:只要模板声明范围内的实体与模板参数之一具有相同的名称,该名称就会隐藏在模板中。如果您在举出例子时遇到问题,很可能您不理解引文的含义。你明白了什么?您难以理解的是什么?
对于那些不想了解该标准的人来说,完成原始引用也很重要:
这有助于理解示例。请注意引号的含义:第一个
N
引用命名空间范围内的typedef
,然后引入模板参数N
。从那时起,模板参数隐藏外部N
,下一次出现的N
引用模板参数而不是外部< code>N(仅在模板的声明范围内)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:
Which helps understanding the example. Note what the quote means: the first
N
refers to thetypedef
at the namespace scope, then a template argumentN
is introduced. From there on, the template argument hides the outerN
, and the next appearance ofN
refers to the template argument and not to the outerN
(only within the declarative scope of the template)当然:
函数中的 n 隐藏了在全局范围内声明的 n。
Sure:
The n in the function hides the one declared at global scope.