struct and default constructor

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 11 02:08:20 PDT 2014


On Sat, 11 Oct 2014 08:41:15 +0000
Nicolas Sicard via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On Friday, 10 October 2014 at 22:34:45 UTC, ketmar via
> Digitalmars-d wrote:
> >> I think I like the idea of the factory method now though, as 
> >> I've learned you can hide a struct inside a function, and then 
> >> call the function to set the struct up properly and return it. 
> >> At least, I'm sure I've seen code that does that..
> > ah, yes, it's "Voldemort type". ;-)
> >
> >   auto thatWhoCantBeNamed () {
> >     static struct A { ... }
> >     return A();
> >   }
> >
> > voila. you have type that you can use but cannot create without
> > factory. but you need to have postblit enabled with this.
> 
> It's not a "Voldemort type" if the struct A is static, is it? You
> can just alias A = typeof(thatWhoCantBeNamed()); and then create
> a new object of the same type.
yes, my bad. i'm so used to write "static" to avoid the things that
compiler can remove for me that my code is polluted with it.

thank you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141011/9b3682f8/attachment.sig>


More information about the Digitalmars-d mailing list