Registered Member
|
I am trying to use Eigen matrices and arrays as fields in struct and running into trouble.
I have a type def statement in a header file: typedef struct { MatrixXd M; } MyStruct In the main program I have the following lines. MyStruct *S; S = (MyStruct*)malloc(sizeof(MyStruct)); If the field were a pointer to an array I'd know what to do next. I am having trouble setting the values to M via a move like S->M = ... To allocate memory I've tried S->M.resize(n,n). I've also tried initializing M in the typedef. Thank you for your help. |
Moderator
|
in C++ you should write:
struct MyStruct { MatrixXd M; }; and use operator new: S = new MyStruct; and then initialize S->M as usual: S->M = MatrixXd::Random(10,10); |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]