www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - No dynamic Arrays in Struct?

reply Manfred Nowak <svv1999 hotmail.com> writes:
void main(){
  struct S{
    int[] map;
    map.length= 1000; // error: no identifier for declarator map.length
  } S s;
}

-manfred
Feb 09 2007
parent reply torhu <fake address.dude> writes:
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.
Feb 10 2007
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
torhu wrote
 You can't have an assignment in the struct definition.
Oooops. Thank you. I was misleaded by the error message. -manfred
Feb 10 2007
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
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
Feb 10 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Feb 10 2007