help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help: How to do a proper dynamic C++ array, new 3.4.2 compile errors


From: Eric
Subject: Help: How to do a proper dynamic C++ array, new 3.4.2 compile errors
Date: Mon, 21 Mar 2005 20:21:37 -0500

I get the error "an array reference cannot appear in a constant-expression"
when compiling the following line of code:  int (*debug)[dims[2]][dims[3]] =
new int[dims[1]][dims[2]][dims[3]];

This code compiled and worked fine previous to GCC 3.4.2.  Am I
approaching this the wrong way?  I am trying to create a dynamically
sized array accessible by "some_array [x] [y] [z] =.... "
Maybe I can change some compiler settings?  I would try 3.4.3, but mingw
doesn't appear to have it ready for windows yet.

I've seen some good examples of 3d arrays using vectors, but at some point I
have to pass an array into FFTW to caculate the fourier transform.  I could 
just
convert it to 1D, but I am curious about this.

here is a snippet of my code that I am debugging:

where "dims" is an array of ints that are > 0
****************
//a test, ive tried these as regular ints and const ints, no difference
int npoints = dims[1];
int nscans = dims[2];
int nslices = dims[3];

//another hunch
const int test = 3;
int test2 = 3;

int (*debug)[dims[2]][dims[3]] = new int[dims[1]][dims[2]][dims[3]];
//fails
 int (*debug2)[nscans][nslices] = new int[npoints][nscans][nslices];
//fails
int (*debug3)[test][test] = new int[test][test][test];  //compiles ok, but
defeats the idea of a dynamic array
int (*debug4)[test2][test2] = new int[test2][test2][test2]; //fails, so it
only likes const ints

****************
I keep seeing that my variables (test2, npoints, etc) "cannot appear in a
constant-expression" either.  Any suggestions?

Thanks for your help,
Eric





reply via email to

[Prev in Thread] Current Thread [Next in Thread]