5
请考虑以下病态的程序:专门的内部类模板的功能的类外定义?
struct S {
template<class T> struct J { };
};
template<>
struct S::J<void> {
void f();
};
template<>
void S::J<void>::f() {} // ERROR
$ clang++ -std=c++11 test.cpp
no function template matches function template specialization 'f'
$ g++ -std=c++11 test.cpp
template-id ‘f<>’ for ‘void S::J<void>::f()’ does not match any template declaration
为什么不的f
定义编译?如何在上面正确定义函数f
?
“*如果您正在定义模板的成员函数*”或模板成员函数,则只需要'template'。 – ildjarn 2015-02-11 13:54:26
@ildjarn更新 – Barry 2015-02-11 14:00:20