我有这个问题相当长的时间 - 我有固定大小的二维数组作为一个类成员
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(); ??? }我想通过指针 M 矩阵之外。这也可能是很简单,但我就是无法找到&放适当的组合; 和 * 等
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.
感谢您的帮助。
推荐答案双* A [3] [3]; 是一个2维数组双* 秒。你想双(* A)[3] [3];。
double *A[3][3]; is a 2-dimensional array of double *s. You want double (*A)[3][3]; .
然后,请注意, A 和 * A 和 ** A 都具有相同的地址,只是不同的类型。
Then, note that A and *A and **A all have the same address, just different types.
制作的typedef可以简化事情:
Making a typedef can simplify things:
typedef double d3x3[3][3];这是C ++,你应该通过引用传递变量,不是指针:
This being C++, you should pass the variable by reference, not pointer:
void getpointeM( d3x3 &matrix );现在,你不需要使用类型名称括号,编译器可以确保你传递正确的大小的数组。
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.
更多推荐
传递指针二维数组C ++
发布评论