dimanche 10 novembre 2019

Why I can't use parametric constructor within a class?

I am using Eigen 3.3.7 library in my code. I can create and fill a vector with data in my main() as follows:

Vector3d H1(0.0, 0.0, 1.0);
Vector3d H2 = {0.0, 0.0, 1.0};
Matrix3d D(3,2); // Matrix is only initialised

However, if I do the same within a class, I get the syntax error:

class data {
    Vector3d H1(0.0, 0.0, 1.0);   //syntax error
    Vector3d H = {0.0, 0.0, 1.0}; //still works
    MatrixXd D(3,2);              //syntax error
};

Question 1:

Why can't I use the same syntax within the body of a class?

How can I define 3-by-2 matrix as an attribute of data with Eigen?

Question 2:

I understand that H1(0.0, 0.0, 1.0) version invokes parametric constructor, however, I don't know what happens under the Vector3d H2 = {0.0, 0.0, 1.0}; line. So what in fact does? And why does it work in the second case?

Aucun commentaire:

Enregistrer un commentaire