Reputation: 785
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
Upvotes: 1
Views: 494
Reputation: 18827
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();
Upvotes: 2