我正在阅读 name lookup并且遇到了下面这句话:
If the name appears immediately to the right of the scope resolution operator :: or possibly after :: followed by the disambiguating keyword template
我确实得到了上面的第一部分,但是“在::之后是消除歧义的关键字模板 - 哇?我迷失在这个部分。
那么什么是“消除歧义的关键字”,什么是“关键字模板”(作者写的好像它们是一回事,至少对我而言) ?
最佳答案
举个例子
template<typename T>
struct S {
template<typename U> static void foo(){}
};
template<typename T>
void bar()
{
S<T>::foo<T>(); // error: < parsed as less than operator
S<T>::template foo<T>(); // OK
}
int main() {
bar<int>();
return 0;
}
关于c++ - 什么是消除歧义的关键字模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48122469/