简体   繁体   English

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

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

I want to write a function which is of struct type, but it returns eigen::matrix type vector (so to say...)我想写一个struct类型的struct ,但它返回eigen::matrix类型向量(可以这么说......)

For example:例如:

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
}

I am unsure about where to declare the eigen::matrix type vector.我不确定在哪里声明eigen::matrix类型向量。 Should it be inside the function or in the struct or should it be a separate struct of eigen::matrix type or any other way is preferred.它应该在函数内部或struct还是应该是eigen::matrix类型的单独struct或任何其他方式是首选。

There is no such thing as "a function of struct type", and your struct declaration syntax is really weird.没有“结构类型的函数”这样的东西,你的结构声明语法真的很奇怪。 You seem to be confusing types with objects.您似乎将类型与对象混淆了。

Here's what I think you need, simply a function that returns an instance of your eigen::Matrix specialisation (which you've named foofoo via a type alias):这是我认为您需要的,只是一个返回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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM