C++ 犰狳c++;铸造双矩阵垫至浮动矩阵fmat

C++ 犰狳c++;铸造双矩阵垫至浮动矩阵fmat,c++,armadillo,C++,Armadillo,我怎样才能把垫子打到fmat上。我的功能之一是返回mat。但是为了内存,我想把它转换成fmat。如何进行类型转换?您可以使用以下命令在矩阵类型之间进行转换: mata=my_函数(); fmat B=转换到::从(A); fmat C=conv_to::from(my_function()); 或者,您可以将函数更改为模板;例如: template <typename T> Mat<T> other_function() { return Mat<T>(

我怎样才能把垫子打到fmat上。我的功能之一是返回mat。但是为了内存,我想把它转换成fmat。如何进行类型转换?

您可以使用以下命令在矩阵类型之间进行转换:

mata=my_函数();
fmat B=转换到::从(A);
fmat C=conv_to::from(my_function());
或者,您可以将函数更改为模板;例如:

template <typename T>
Mat<T> other_function() {
  return Mat<T>(4,4);
}

...

fmat D = other_function<float>();
mat F = other_function<double>();
模板
Mat other_函数(){
返回垫(4,4);
}
...
fmat D=其他_函数();
mat F=其他_函数();

vector呢?例如,双向量向量到浮点向量fvec?上述解决方案也适用于向量。谢谢
template <typename T>
Mat<T> other_function() {
  return Mat<T>(4,4);
}

...

fmat D = other_function<float>();
mat F = other_function<double>();