开发者

Allocate multi-dimensional array in D at runtime

开发者 https://www.devze.com 2023-03-17 08:37 出处:网络
Is it possible to allocate 2-dimensional arrays (and higher) in D? The following does not work: void create2DArray(uint w, uint h) {

Is it possible to allocate 2-dimensional arrays (and higher) in D?

The following does not work:

void create2DArray(uint w, uint h) {
    double[][] histogram = new double[w][h];
}

however, the following compiles fine:

void create1DArray(uint w) {
    double[] histogram = new double开发者_C百科[w];
}


You need to use constructor syntax like this:

void create2DArray(uint w, uint h) {
    double[][] histogram = new double[][](w, h);
}

That works fine, at least in D2.


Here is a proposal http://www.tcm.phy.cam.ac.uk/~nn245/documents/D-multidimarray.html

Looks like you have to allocate each row for itself with a loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消