I'm used to C# and Matlab and I'm trying to do a simple C++ program using Eigen template library for linear algebra.
Sorry but I'm struggling with the basics:
- Store Matrix3d Eigen in struct
- Pass as parameter to a method
- Return a struct containing Eigen objects references.
Sample code (it is not compiling, C# developer in pain here):
struct MyStruct
{
Matrix3d* K1; //Is that the right way, using pointers?
Matrix3d* K2;
};
int main()
{
//Case 1
MyStruct* A = new MyStruct();
A->K1 = &(Matrix3d)Matrix3d::Random();
MyStruct* result = MyMethod(A);
//Case 2 - I noticed that everybody uses case 1, what is the difference?
MyStruct B;
B.K1 = &(Matrix3d)Matrix3d::Random();
B.K1(0,0) = 1; // Not working. How can I access it?
MyStruct* result = MyMethod(&B);
}
*MyStruct DoSomething(MyStruct& input)
{
MyStruct result;
result.K1 = ...
return &result;
}