gpt4 book ai didi

c++ - 模板参数的潜在范围是什么?

转载 作者:行者123 更新时间:2023-11-30 02:08:54 25 4
gpt4 key购买 nike

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

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;

在这种情况下,“潜在范围”是什么意思?任何人都可以提供这样的例子吗?

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

最佳答案

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.

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

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

第二个 i 的潜在范围被排除在第一个 i 的范围之外。换句话说,这准确地描述了名称隐藏适用的地方。你引用的那一点说模板名称也可以隐藏。

关于c++ - 模板参数的潜在范围是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5987213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com