Expression can not be a function
, but my expression is not a function, it is a variable.
Show my code.
class Data {
public:
Data(int rows, int partid, vector<MatrixXd*> * res, MatrixXd * a)
{
_rows = rows;
_partid = partid;
_res = res;
_a = a;
}
int _rows;
int _partid;
vector<MatrixXd*> * _res;
MatrixXd * _a;
};
[snippet]
void * partitionFunc(void * arg)
{
Data * data = (Data *)arg;
MatrixXd * m;
int dim = data->_rows / data->_res->size();
for (int i = 0; i < dim; i ++)
{
for (int j = 0; j < dim; j ++)
{
m = (*(data->_res))[data->_partid];
(*m)(i, j) = data->_a(dim*data->_partid+i, dim*data->_partid+j);
}
}
pthread_exit(NULL);
}
When compiling the code it returned
In file included from main.cpp:2:0:
solutions.h: In function ‘void* partitionFunc(void*)’:
solutions.h:86:75: error: expression cannot be used as a function
(*m)(i, j) = data->_a(dim*data->_partid+i, dim*data->_partid+j);
^
solutions.h: In function ‘void* partitionFunc(void*)’:
solutions.h:86:75: error: expression cannot be used as a function
(*m)(i, j) = data->_a(dim*data->_partid+i, dim*data->_partid+j);
But the m
is a matrix, and (*m)(i, j)
is to get the value in row i+1, column j+1.
How should I avoid such error.
It meant data->_a
is not function (note the position of ^
). You should do the same thing to data->_a
as m
, i.e. using operator*
since it's a pointer to MatrixXd
.
(*m)(i, j) = (*data->_a)(dim*data->_partid+i, dim*data->_partid+j);