c++ - 什么是消除歧义的关键字模板?

标签 c++

我正在阅读 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;
}

More details

关于c++ - 什么是消除歧义的关键字模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48122469/

相关文章:

c++ - 通过包含模板的继承链的 static_cast 将无法编译

c++ - QDBusAbstractAdaptor 与 QDBusAbstractInterface

c++ - 如何在不调用函数的情况下在 Linux 中检索处理器时间?

c++ - 如何处理 windows.h 中的 max 宏与 std 中的 max 冲突?

c++ - 如何在现代 C++ 中表达引用关系而不表达所有权?

C++ Winsock 套接字错误 : 10038 (WSAENOTSOCK)

c++ - 在 Windows 小型转储文件中嵌入线程名称

c++ - linux + Visual Studio 2013 + VisualGDB, undefined reference 'dlopen'

c++ - Qt 5.0.2 应用程序的可移植性问题。如何制作简约的Qt包?

c++ - std::set with string key 和潜在的效率损失