我有一个类似这样的类(class)
template<class T>
class Matrix {
...
template<class T2> auto dot(Matrix<T2> const& other);
}
这是我的实现,在头文件中的声明下:
template<class T, class T2>
auto Matrix<T>::dot(Matrix<T2> const& other) {
[impl]
}
我收到的错误如下所示:
(C2244) 'Matrix<T>::dot' : unable to match function definition to an existing declaration
我哪里出错了?
最佳答案
语法错误。您在具有模板参数 T
的类模板中拥有一个具有模板参数 T2
的函数模板。它必须这样定义:
template<class T>
template<class T2>
auto Matrix<T>::dot(Matrix<T2> const& other) {
}
关于c++ - 头文件中模板类实现的模板成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55396217/