传递指针二维数组C ++

编程入门 行业动态 更新时间:2024-10-26 02:30:04
本文介绍了传递指针二维数组C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个问题相当长的时间 - 我有固定大小的二维数组作为一个类成员

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 ++

本文发布于:2023-07-29 00:34:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   指针

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!