二维数组到指针的转换

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].

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

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

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)