如何修复此语法错误?
struct A {
template < typename T >
void f () {}
};
template < typename C, typename U >
struct B {
void g () {
U::f < C > (); // expected primary-expression before »>« token
}
};
int main () {
B<int,A> b;
b.g ();
}
最佳答案
U
是依赖类型,因此您需要指定 f
是模板成员:
U::template f<C>();
当 U
为 A
时,这仍然无效,因为 f
不是 static
的成员A
。
关于C++模板语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3621719/