I have the following class:
class Foo
{
public:
Foo(double a, double b, double c, double d, double e)
// This does not work:
// : m_bar(a, b, c, d, e)
{
m_bar << a, b, c, d, e;
}
private:
// How can I make this const?
Eigen::Matrix<double, 5, 1, Eigen::DontAlign> m_bar;
};
How Can I make m_bar const and initialize it width a to f as values in the constructor? C++11 would also be fine, but initializer lists don't seem to be supported by eigen...
Simplest solution I see since the class also defines a copy constructor:
class Foo
{
public:
Foo(double a, double b, double c, double d, double e) :
m_bar( (Eigen::Matrix<double, 5, 1, Eigen::DontAlign>() << a, b, c, d, e).finished() )
{
}
private:
const Eigen::Matrix<double, 5, 1, Eigen::DontAlign> m_bar;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With