Structs may not be nested inside structs, only classes

Mon Aug 27, 2018 3:15 pm

I'm not sure if this is intentional, but I notice that while structs can be nested inside classes, they cannot be nested inside other structs.

Because nesting can be helpful for reducing the chance of namespace collisions, please consider allowing that.

Re: Structs may not be nested inside structs, only classes

Tue Aug 28, 2018 10:47 am

If that were true, Line structs wouldn't be able to store Vertex structs and so on. But then again, they're native...

Are you trying to store structs of the same type into itself? Try making it 'readonly'. That's how the Sector struct does it with the heightsec variable which is also a Sector struct.

No guarantees it'll work, that's just a theory.

Re: Structs may not be nested inside structs, only classes

Tue Aug 28, 2018 11:02 am

No. He's talking about defining structs inside structs.
I'm pretty sure this is intentional. There's nothing in the ZScript syntax to allow structs nested in structs.

Re: Structs may not be nested inside structs, only classes

Tue Aug 28, 2018 11:08 am

Code:
Class aa
{
   Struct bb
   {
      int volt;
   };
}


Oooh, I see now. Huh. Didn't even know that was doable. TIL!

Re: Structs may not be nested inside structs, only classes

Tue Aug 28, 2018 11:32 am

This is certainly an oversight. The compiler backend can definitely handle such constructs, but it seems the grammar is incomplete.