[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help: How to do a proper dynamic C++ array, new 3.4.2 compile errors
From: |
Ulrich Eckhardt |
Subject: |
Re: Help: How to do a proper dynamic C++ array, new 3.4.2 compile errors |
Date: |
Tue, 22 Mar 2005 17:56:02 +0100 |
User-agent: |
KNode/0.8.1 |
Eric wrote:
> 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]];
I'm not sure what it is you are doing there, but most probably the problem
can be reduced to this:
int size = ...;
float array[size];
which is not valid C++ (and has never been). Yes, there is a GCC extension
that makes this work, but it's not C++.
> This code compiled and worked fine previous to GCC 3.4.2. Am I
> approaching this the wrong way?
If I were you, I'd consider using typedefs. As soon as you have a variable
in one of the typedefs, you also know that you did something outside of
C++.
In case you're not doing this for fun or education, take a look at boost or
blitz, I think both have n-dimensional array types.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/