Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?
Jeremy DeHaan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 16 22:04:14 PST 2015
On Thursday, 17 December 2015 at 04:59:20 UTC, Jakob Ovrum wrote:
> On Thursday, 17 December 2015 at 04:05:30 UTC, Jeremy DeHaan
> wrote:
>> http://dpaste.com/3FH3W13
>
> Also, I would be wary of lazy initialization. We have bad
> experiences with it for AAs and standard containers. A typical
> example would be:
>
> void foo(Wrapper w)
> {
> ...
> w.doTheThing();
> ...
> }
>
> void main()
> {
> Wrapper w;
> foo();
> w.inspect(); // `w` is still a null reference here
> }
Thanks for the heads up. I'll think more on this, but you made a
good point here.
And I guess what I was talking about before is that using a
factory method feels klunky to me. If the things I am wrapping
had been written in D they could use default initialization, so
it feels wrong to do otherwise. I also just don't really like
factory methods. They feel like a workaround that the end user
has to deal with. But that's just me.
More information about the Digitalmars-d-learn
mailing list