I`m a beginner of C++. Any help will be very appreciated!
I have an issue passing a matrix to a function in C++. There is the function i want to create:
#include <stdio.h>
#include <Eigen/Core>
#include <Eigen/Eigen>
#include<Eigen/Geometry>
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture;
using namespace std;
If you want to pass a multidimensional array, you must explicitly state its column size
1 2 3
#define COL_SIZE 5
float matOpt (int nrows, int Y[][COL_SIZE], int X[][COL_SIZE]);
So you can't use function parameters to specify the array size of subsequent function parameters. If your arrays are going to have a set number of columns, then you can hard-code them in. If not, you'll need to study up and use pointers.
Thank you for your advice. Every time i need to read different data, and the ncols of array is also different. And in my opinion, using pointers passes header elements address to the function rather than the whole matrix. And i need whole matrix to manipulate. So any other advice?
I see what you mean, but how could i set X or Y matrix as the parameter of the function for matrix manipulation, if taking Eigen::MatrixXf to begin with?
And there is still something obscure between 2D array in C-style and matrix in Eigen.