如果我设置了模板类foo:func
template<typename T>
class foo{
public:
template<typename U> static void func(){}
};
int main(){
foo<int>::func<long>();
}
一切正常。当我尝试从模板类中调用foo::func
时
template<typename T>
class foo{
public:
template<typename U>
static void func(){}
};
template<typename T,typename U>
class bar{
public:
bar(){
foo<T>::func<U>();
}
};
int main(){
bar<int,long> b;
foo<int>::func<long>();
}
我收到以下编译错误:
main.cpp: In constructor ‘bar<T, U>::bar()’:
main.cpp:13:19: error: expected primary-expression before ‘>’ token
foo<T>::func<U>();
^
main.cpp:13:21: error: expected primary-expression before ‘)’ token
foo<T>::func<U>();
^
如何从模板类foo::func
中调用bar
?