struct and default constructor
Nicolas Sicard via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 11 01:41:15 PDT 2014
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.
--
Nicolas
More information about the Digitalmars-d
mailing list