在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中引入? – 2012-02-17 19:51:54