特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数

Eigen::Matrix<double,1,3> return type function in a struct type function

本文关键字:函数 类型 返回类型 结构 lt 矩阵 双精度 特征 gt      更新时间:2023-10-16

我想写一个struct类型的函数,但它返回eigen::matrix类型的向量(可以说…(

例如:

struct foo (){ double a,b,c; };  
foo FOO(){  
typedef eigen::Matrix<double,1,3> foofoo;
foo f;
// .....                 // some expressions that generate some numerical values
f.a; f.b;f.c;         // numerical values are put in here
foofoo<<f.a, f.b,f.c; // assigned to the eigen::matrix
return foofoo;        // attempt to return eigen::matrix type vector
}

我不确定在哪里声明eigen::matrix类型向量。它应该在函数内部还是在struct中,或者它应该是eigen::matrix类型的单独struct,或者任何其他方式都是优选的。

没有"结构类型的函数"这回事,而且结构声明语法真的很奇怪。你似乎混淆了类型和对象。

以下是我认为您需要的,只是一个返回eigen::Matrix专业化实例的函数(您已通过类型别名将其命名为foofoo(:

struct foo
{
double a, b, c;
};
using foofoo = eigen::Matrix<double, 1, 3>;
foofoo FOO()
{
foofoo result;
foo f;
// ... populate members of f ...
result << f.a, f.b, f.c;
return result;
}