简体   繁体   中英

initializing a static eigen matrix with “comma initialization”

I'm using the Eigen Library here: http://eigen.tuxfamily.org/index.php?title=Main_Page

When trying to compile this, it returns

error: expected constructor, destructor, or type conversion before '.'

complaining about the lines where i add the xaxis...zaxis to the matrix. is it possible it's because gcc4.3 (which is the compiler i'm using) doesn't like this type of initialization because the dot usually is a function call (which wouldn't work on an uninitialized object)?

but to me it seems to follow exactly the tutorial example here: http://eigen.tuxfamily.org/dox/TutorialAdvancedInitialization.html , except for the static, but the error is the same without it. I tried using the comma separated initialization but again it's the same.

// axis system
static Eigen::Matrix<double, 3, 1>    s_xAxis(1.,0.,0.);            //!< global x Axis;
static Eigen::Matrix<double, 3, 1>    s_yAxis(0.,1.,0.);            //!< global y Axis;
static Eigen::Matrix<double, 3, 1>    s_zAxis(0.,0.,1.);            //!< global z Axis;

// origin
static Eigen::Matrix<double, 3, 1>    s_origin(0.,0.,0.);           //!< origin position

static Eigen::Matrix<double, 3,3>     s_idRotationZinverse;
s_idRotationZinverse.col(0) << s_yAxis;
s_idRotationZinverse.col(1) << s_xAxis;
s_idRotationZinverse.col(2) << -s_zAxis;

Oh, I got this.

This code:

s_idRotationZinverse.col(0) << s_yAxis;

isn't a declaration; it's a statement that has to be inside a function body.

You're probably trying to execute it outside of any function, which is syntactically incorrect and causes the error you mentioned .

You might have been tricked by the Eigen documentation, which calls this syntax "comma initialization" where it should be "comma assignment" or so. Initialization is when you give the variable a value when it's defined, not as a separate step. Initialization is syntactically a part of the declaration, so it can be done outside of function bodies.

I suggest to fork Eigen to support the new std::initializer_list -based initialization (if it's not done yet) and submit a pull request.

你有没有尝试过:

s_idRotationZinverse.col(0) = s_yAxis;

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