struct variable initialized with void.
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 31 10:00:25 PDT 2015
On Tue, Mar 31, 2015 at 03:23:11PM +0000, Adam D. Ruppe via Digitalmars-d-learn wrote:
[...]
> 3) You are initializing a private member with default construction
> turned off. Here, "Struct s;" wouldn't compile because of the disabled
> default constructor, but you need to set it up anyway. So you do
> "Struct s = void; s.values = something;" - void to tell the compiler
> you know what you're doing, then you quickly initialize it to what it
> needs to be. I say in a private member because you'd be bypassing the
> object's requirements this way, so you are responsibile for making
> sure the values are indeed valid before using the object.
Ooh, I never thought of this before. Nice!! I'll have to keep this in
mind next time I need to store a non-default-constructible object as an
aggregate member. Thanks for the tip!
T
--
Lawyer: (n.) An innocence-vending machine, the effectiveness of which depends on how much money is inserted.
More information about the Digitalmars-d-learn
mailing list