3 ms·
> it is the only way to call the no-arguments constructor for a variable on the stack. Is that really true? Ouch. In many languages that wouldn't feel crazy, b
by tialaramex 3y ago
> it is the only way to call the no-arguments constructor for a variable on the stack.
Is that really true? Ouch. In many languages that wouldn't feel crazy, but in a language where there's a whole book about initialization https://leanpub.com/cppinitbook https://leanpub.com/cppinitbook that feels kinda silly.
- tsimionescu 3y agoA sibling response pointed out that adding an empty pair of braces (an ampty initializer list) after the var name can also invoke the no-args constructor, but it can also do other things depending on the class. So yes, I believe this is the only way of explicitly calling the no-args constructor whole in-place on a stack variable. Ideally the syntax `T var();` would have worked as well, but it turns out that it would be ambiguous with declaring a local function named var that takes no arguments and returns a T...