头文件中模板类实现的模板成员

魔力士

我有一个看起来像这样的课程

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

我要去哪里错了?

PW

语法错误。您在具有template parameterT2的类模板中具有具有template参数的功能模板T必须这样定义:

template<class T>
template<class T2> 
auto Matrix<T>::dot(Matrix<T2> const& other) {

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章