Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 10, 2007 No dynamic Arrays in Struct? | ||||
---|---|---|---|---|
| ||||
void main(){ struct S{ int[] map; map.length= 1000; // error: no identifier for declarator map.length } S s; } -manfred |
February 10, 2007 Re: No dynamic Arrays in Struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote:
> void main(){
> struct S{
> int[] map;
> map.length= 1000; // error: no identifier for declarator map.length
> } S s;
> }
You can't have an assignment in the struct definition. Try just using 'int[1000] map;' instead. Or set the size in a function, if you want to have a dynamic array with preset length.
|
February 10, 2007 Re: No dynamic Arrays in Struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | torhu wrote
> You can't have an assignment in the struct definition.
Oooops. Thank you. I was misleaded by the error message.
-manfred
|
February 10, 2007 Re: No dynamic Arrays in Struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote:
> torhu wrote
>> You can't have an assignment in the struct definition.
>
> Oooops. Thank you. I was misleaded by the error message.
>
> -manfred
Try
struct S {
int[] map = new int[1000];
}
/Should/ work I believe, if you really want the length dynamic.
-- Chris Nicholson-Sauls
|
February 11, 2007 Re: No dynamic Arrays in Struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | "Chris Nicholson-Sauls" <ibisbasenji@gmail.com> wrote in message news:eql1r2$a2f$1@digitaldaemon.com... > Manfred Nowak wrote: >> torhu wrote >>> You can't have an assignment in the struct definition. >> >> Oooops. Thank you. I was misleaded by the error message. >> >> -manfred > > Try > struct S { > int[] map = new int[1000]; > } > > /Should/ work I believe, if you really want the length dynamic. You can't have non-static initializers for aggregate member declarations. That's one thing I wish D would take from Java/C#... |
Copyright © 1999-2021 by the D Language Foundation