简体   繁体   中英

How to create static member variable with Eigen types library

I am trying to implement a class that has some static member from Eigen library types, nevertheless I am getting the following compiler error

kalman.cpp:3:28: error: expected initializer before ‘<<’ token
 Eigen::Matrix2d Kalman::AA << 1,2,3,4;
                            ^

which I do not know how to solve it. Here , in the documentation library there is the section Comma-initialization which describes the initialition format chosen. Of course, in a simple main source code like this

#include <iostream>
#include "Eigen/Dense"
int main()
{
  Eigen::Matrix2d m;
  m << 1,2,3,4;
  std::cout << m << std::endl;
}

every works as expected. But, when I try to do this with an static member variables of type Eigen::Matrix2d as follows

header

#ifndef KALMAN_H
#define KALMAN_H

#include <iostream>
#include "Eigen/Dense"

class Kalman{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
    static Eigen::Matrix2d AA;
};
#endif /* KALMAN_H */

source

#include "kalman.hpp"

Eigen::Matrix2d Kalman::AA << 1,2,3,4;

I got the mentioned error. I think that this could be related of some sort of how to create static member objects, but to be sincere I do not know. Any tips or recommend content it will be really appreciate.

Thanks

The << is not equivalent to an assignment operator, it writes values into an existing matrix. You can do what you want with this:

Eigen::Matrix2d Kalman::AA = (Eigen::Matrix2d() << 1,2,3,4).finished();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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