C++에서는 자체 템플릿 인 객체에 대해 템플릿 함수를 특수화하려고합니다. test.h : 여기 템플릿 기반 클래스에 대한 템플릿 함수의 특수화
는 기본 예입니다template <class T>
class myC {
T x;
};
template <class U>
void f(U y) {
}
template <>
template <class T>
void f<myC<T> >(myC<T> y) {
}
Test.cpp에
#include "test.h"
int main() {
myC<double> m;
f(m);
}
GCC 4.6.1 나에게 다음과 같은 오류 메시지가 있습니다 :
In file included from test.cpp:1:0:
test.h:13:25: error: too many template parameter lists in declaration of ‘void f(myC<T>)’
test.h:13:6: error: template-id ‘f<myC<T> >’ for ‘void f(myC<T>)’ does not match any template declaration
test.h:13:25: note: saw 2 ‘template<>’, need 1 for specializing a member function template
을 가능한가요? 아니면 같은 목표를 달성하기위한 또 다른 방법이 있습니까?
C++ 11에서 소개되지 않았습니까? –