1
假设我们有下面的类模板:类模板和功能明确的专业化
template<typename T, size_t m, size_t n>
class Matrix {
/* Implementation/Declaration is probably irrelevant and has been omitted. */
};
我想专攻某一功能为我的模板类。
template<> template<typename T, size_t m, size_t n>
inline std::wstring Microsoft::VisualStudio:CppUnitTestFramework::ToString(const Matrix<T, m, n> &mtrx) {
/* Definition omitted */
}
(是的,我是专业的功能是一个真正的函数,应该不会太难找。)
我看不出有任何理由,为什么上面的代码是错误的,但编译(你问之前,适当的文件已被包括在内),当我得到以下(非常无益的)错误消息:
C2244: 'ToString': unable to match function definition to an existing declaration
因为人们难免会问它,我还不如包括I的功能原型专营:
template <typename Q> static std::wstring ToString (const Q& q);
而且,我没有专门与没有模板参数的类(例如:std :: string)相关的问题。
摆脱'template <>'部分。 –
我已经试过了。它不起作用。 (完全相同的错误信息。) – Isaiah
你是否在名称空间内首先声明它? –