Jul 4, 2013 at 12:33pm UTC
Dear all,
I have found a lot of solutions using Google but no solution did work.
Could you please tell me how we can return a 3x3 matrix in c++ function.
My code is:
1 2 3 4 5 6 7 8
double *computeA()
{
double *A = new double [2][2];
// some operations on A and then return
return A;
}
The error that I have in this case is:
error C2440: 'initializing' : cannot convert from 'double (*)[2]' to 'double *'
Thank you in advance
Last edited on Jul 4, 2013 at 12:50pm UTC
Jul 4, 2013 at 1:01pm UTC
Thank you so much Peter87.
In the case of std::array<std::array<double , 2>, 2> A;
which I prefer, how we can scan the elements? using iterator as the case in vector?
Jul 4, 2013 at 1:06pm UTC
Iterators or by index like normal arrays.
Jul 4, 2013 at 1:09pm UTC
Thank you ;)
Have a nice day.
Jul 4, 2013 at 1:39pm UTC
std::array was added in C++11 so maybe you have to turn on C++11 features somehow. If you are using GCC you can do that by passing -std=c++11 (or -std=c++0x) to the compiler.
Jul 4, 2013 at 1:47pm UTC
I am using Visual c++ 2008.