I’m having this problem for quite a long time – I have fixed sized 2D array as a class member.
class myClass
{
public:
void getpointeM(...??????...);
double * retpointM();
private:
double M[3][3];
};
int main()
{
myClass moo;
double *A[3][3];
moo.getpointM( A ); ???
A = moo.retpointM(); ???
}
I’d like to pass pointer to M matrix outside. It’s probably very simple, but I just can’t find the proper combination of & and * etc.
Thanks for help.
double *A[3][3];is a 2-dimensional array ofdouble *s. You wantdouble (*A)[3][3];
.Then, note that
Aand*Aand**Aall have the same address, just different types.Making a typedef can simplify things:
This being C++, you should pass the variable by reference, not pointer:
Now you don’t need to use parens in type names, and the compiler makes sure you’re passing an array of the correct size.