将2D数组转换为指针到指针 [英] conversion of 2D array to pointer-to-pointer

查看:168
本文介绍了将2D数组转换为指针到指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Activity solution[a][b];

...

Activity **mother = solution;

我想将对象的2D数组转换为指针指针。我该如何做到这一点;

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

我在google上搜索过。但是我发现只有一个维数组的例子。

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

推荐答案

只是转换不会帮助你。在2D数组类型和指针到指针类型之间没有任何类型的兼容性。这样的转换是没有意义的。

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] 将允许您访问解决方案[i] [j]

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

这篇关于将2D数组转换为指针到指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆