Page 1 of 1

Structs may not be nested inside structs, only classes

Posted: Mon Aug 27, 2018 3:15 pm
by argv
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

Posted: Tue Aug 28, 2018 10:47 am
by Major Cooke
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

Posted: Tue Aug 28, 2018 11:02 am
by phantombeta
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

Posted: Tue Aug 28, 2018 11:08 am
by Major Cooke

Code: Select all

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

Posted: Tue Aug 28, 2018 11:32 am
by Graf Zahl
This is certainly an oversight. The compiler backend can definitely handle such constructs, but it seems the grammar is incomplete.