Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么会出现此错误,我该如何解决?
template<typename T> struct foo { template<size_t N> void hello() {} }; template<typename T> struct bar { void world() { foo<T> f; f.hello<0>(); //Error: Expected expression } };
您需要使用template消歧器,因此编译器将知道它应解析hello为模板成员函数的名称,以及随后的<和>作为分隔模板参数的尖括号:
template
hello
<
>
f.template hello<0>(); //^^^^^^^^