这不编译:
template<class X> struct A {
template<int I> void f() {}
};
template<class T> void g()
{
A<T> a;
a.f<3>(); // Compilation fails here (Line 18)
}
int main(int argc, char *argv[])
{
g<int>(); // Line 23
}
Run Code Online (Sandbox Code Playgroud)
编译器(gcc)说:
hhh.cpp:在函数'void g()'中:
hhh.cpp:18:错误:')'令牌之前的预期primary-expression
hhh.cpp:在函数'void g()[with T = int]'中:
hhh.cpp:23:从这里实例化
hhh.cpp:18:错误:无效使用成员(你忘了'&'?)
谁能解释为什么会这样?有没有办法让它发挥作用?