Simple code that won't compile
ginophi
ginophi at fjw3n90v.com
Sat Jul 7 13:00:39 PDT 2007
Thanks for the quick reply. But I forgot to put a 'final' in there. Why
would it work with 'const int b = 1;' and not 'final int b = 1;' ?
"Deewiant" <deewiant.doesnotlike.spam at gmail.com> wrote in message
news:f6oqhj$rta$1 at digitalmars.com...
> ginophi wrote:
> > My very simple test code
> >
> > void main()
> > {
> > struct test
> > {
> > int a;
> > }
> >
> > int b = 1;
> > test name[b];
> > }
> >
> > doesn't compile and gives these errors:
> >
> > test.d(9): Error: Integer constant expression expected instead of b
> > test.d(9): Error: Integer constant expression expected instead of
> > cast(uint)b
> > test.d(9): Error: Integer constant expression expected instead of
> > cast(uint)b
> > test.d(9): Error: Integer constant expression expected instead of
> > cast(uint)b
> >
> > What am I doing wrong?
> >
>
> You're not reading the error message: "Integer constant expression
expected
> instead of b". b isn't constant, hence it doesn't work.
>
> Either make b constant ("const int b = 1"), or use a dynamic array:
>
> auto name = new test[b];
>
> --
> Remove ".doesnotlike.spam" from the mail address.
More information about the Digitalmars-d-learn
mailing list