[sclug] g++ c++ question
Tim Sutton
t.sutton at reading.ac.uk
Sat Oct 25 09:05:53 UTC 2003
Hi
Many thanks for your reply - that seems to sort my problem out.
Regards
Tim
On Thursday 11 September 2003 14:40, Simon Heywood wrote:
> On Thu, Sep 11, 2003 at 03:14:40PM +0100, Tim Sutton wrote:
> > dataprocessor.cpp:780: error: ISO C++ forbids variable-size array `
> >
> > The offending code snippet looks like this:
> >
> > int myArrayLengthInt = theClimateVector.size();
> > float myClimateArray[myArrayLengthInt];
>
> I'm surprised that this compiled at all. You're generally not allowed to
> create an array using a variable as the array size; one tends to use a
> compile time constant for such things.
>
> The C way to do it is with malloc() but in C++ you can do something like
> this.
>
> float *myClimateArray = new float[theClimateVector.size()];
>
> Then you can use things like "myClimateArray[0] = 2.71828f". Not
> particularly unpleasant.
>
> > 1) Did gcc / g++ 3.3 introduce some incompatiblility / stricter standards
> > checking that is affecting me?
>
> Presumably.
>
> S.
> _______________________________________________
> sclug mailing list
> sclug at sclug.org.uk
> http://www.sclug.org.uk/mailman/listinfo/sclug
--
Tim Sutton
BDWorld Middleware Programmer
-------------------------------------------------------------------
BiodiversityWorld Project
Centre for Plant Diversity & Systematics
School of Plant Sciences
The University of Reading
Reading, RG66AS, UK
Web : www.bdworld.org
Phone : +44-(0)118-378-6052
Email : t.sutton [at] reading.ac.uk
(email preferred method of correspondence)
-------------------------------------------------------------------
More information about the Sclug
mailing list