模板参数的潜在范围是什么? [英] What is the potential scope of a template parameter?

查看:142
本文介绍了模板参数的潜在范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ISO草案n3290第3.3.9节第5段的一点:

A point from ISO draft n3290 section 3.3.9 paragraph 5:


因为模板参数的名称不能在其潜在
范围(14.6.1),模板参数的范围通常是其潜在范围。但是,
仍然可以隐藏模板参数名称;

Because the name of a template parameter cannot be redeclared within its potential scope (14.6.1), a template parameter’s scope is often its potential scope. However, it is still possible for a template parameter name to be hidden;

潜在范围这个上下文?任何人都可以提供这样的例子吗?

What does "potential scope" mean in this context? Can anybody provide an example of such?

草案链接n3290: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3290.pdf

draft link n3290: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3290.pdf

推荐答案


3.3.1:声明的 scope
与其潜在范围相同,除非
潜在范围包含同名的另一个
声明。在
情况下,内部(包含)
声明性区域中的
声明的潜在范围
中排除 scope <

3.3.1 : The scope of a declaration is the same as its potential scope unless the potential scope contains another declaration of the same name. In that case, the potential scope of the declaration in the inner (contained) declarative region is excluded from the scope of the declaration in the outer (containing) declarative region.

通常情况下,这指的是这样的情况:

Normally, this refers to cases like this:

void Foo(int i) {
  {
    int i = 5;
    std::cout << i;
  }
  std::cout << i;
};

第二个 i 的潜在范围不包括在第一个 i 的范围之内。换句话说,这正好描述了名称隐藏适用的地方。你引用的位说,模板名称也可以隐藏。

The potential scope of the second i is excluded from the scope of the first i. In other words, this describes precisely where name hiding applies. The bit you quote says that template names can be hidden, too.

这篇关于模板参数的潜在范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆