二维数组到指针的转换

conversion of 2D array to pointer-to-pointer(二维数组到指针的转换)
本文介绍了二维数组到指针的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

Activity solution[a][b];

...

Activity **mother = solution;

我想将对象的二维数组转换为指针到指针.我该怎么做;

I want to convert 2D array of objects to pointer-to-pointer. How can I do this;

我在谷歌上搜索过.但是我只找到了一维数组示例.

I searched it on google. however I found only one dimension array example.

推荐答案

这里仅仅进行转换对您没有帮助.二维数组类型和指针类型之间没有任何类型的兼容性.这种转换毫无意义.

A mere conversion won't help you here. There's no compatibility of any kind between 2D array type and pointer-to-pointer type. Such conversion would make no sense.

如果你真的需要这样做,你必须引入一个额外的中间行索引"数组,它将弥合二维数组语义和指针到指针语义之间的差距

If you really really need to do that, you have to introduce an extra intermediate "row index" array, which will bridge the gap between 2D array semantics and pointer-to-pointer semantics

Activity solution[a][b];

Activity *solution_rows[a] = { solution[0], solution[1] /* and so on */ };

Activity **mother = solution_rows;

现在访问 mother[i][j] 将使您可以访问 solution[i][j].

Now accessing mother[i][j] will give you access to solution[i][j].

这篇关于二维数组到指针的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)