开发者

Allocate multi-dimensional array in D at runtime

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜