[英]Scope resolution operator and dependent name
我有以下测试代码
#include <iostream>
template <typename T>
struct PS
{
template <typename U>
static void foo()
{
std::cout<<"Some test code";
}
};
template <typename T>
void bar()
{
PS<T>::template foo<T>(); //won't compile without `::template`
}
int main()
{
bar<int>();
}
ISO C ++ 03 14.2/4
:说
当成员模板专业化的名称出现之后。 或 - >在postfix-expression中,或在qualified-id中的nested-name-specifier之后,postfix-expression或qualified-id显式依赖于template-parameter(14.6.2),成员模板名称必须是以关键字模板为前缀。 否则,假定该名称命名非模板 。
标准谈到->
和.
但不是关于::
。 它是C ++ 03标准中的缺陷还是我遗漏了什么? 有人请赐教。
但是, N3126
的措辞已经改变
当成员模板专业化的名称出现之后。 或 - >在post fi x-expression中或在quali fi ed-id中的嵌套名称指定符之后,post fi x-expression的对象或指针表达式或者qual-fi-id中的嵌套名称-peci fi er取决于模板参数(14.6.2) 但不引用当前实例化的成员(14.6.2.1),成员模板名称必须由关键字模板预先设定。 否则,假定该名称命名非模板。
有人可以给出一个例子来说明在C ++ 0x的上下文中but does not refer to a member of the current instantiation
什么but does not refer to a member of the current instantiation
吗?
-PS
标准谈到
->
和.
但不是关于::
。
范围解析运算符( ::
)是合格-ID的部分提到了“或在合格-ID 嵌套名称说明符后”。
C ++ 0x中的附加措辞是CWG缺陷224的解决方案的一部分。 实际上,依赖名称的定义已经改变:
关于名称是依赖还是非依赖的决定应该基于查找,而不是基于名称的形式:如果名称可以在定义上下文中查找而不能作为专业化的结果,则名称应该是非依赖的。
有人可以给出一个例子来说明“但是没有引用当前实例化的成员”意味着在C ++ 0x的上下文中吗?
我不知道这是否实际上在C ++ 03和C ++ 0x的实现之间表现不同。
template< typename Q >
struct A {
template< typename T >
void f( T );
void g() {
this->f< Q >( 5 ); // member of current instantiation is not ambiguous
A< identity<Q> >().template f< 5 >(); // suppose A is partially
// specialized on identity. Legal but confusing; need help from template keyword.
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.