Who's using structs nested in functions?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Oct 22 07:07:15 PDT 2009
Refer to:
http://www.digitalmars.com/d/2.0/struct.html
and scroll down to the last section, "Nested Structs". A struct defined
inside a function has a hidden pointer to that function's stack frame
and therefore can use function's local variables.
Nested classes do a similar trick, but for those there's a bit of
motivation - you could create a nested class and use it as a sort of
closure by returning a base class or interface of it.
With nested structs, however, you can't do much. You can pass them to a
template, but I can't see some solid use cases there. My understanding
is that nested structs have been implemented for completeness and
consistency with nested classes.
Any good example of nested struct uses?
Andrei
More information about the Digitalmars-d
mailing list