Who's using structs nested in functions?
Michel Fortin
michel.fortin at michelf.com
Thu Oct 22 10:32:15 PDT 2009
On 2009-10-22 10:07:15 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> 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?
I tried implementing things using nested structs in my mfr.xml
module[1] but, for some reasons I don't remember anymore (template
issues?), I wasn't too successful and ended up creating anonymous scope
classes. All this because of the lack of nested overloaded functions.
[1]: see:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=98861
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list