3 ms·
How can {} return a Badge object? Some kind of operator overload?
by nisuni 7y ago
How can {} return a Badge object? Some kind of operator overload?
- antisemiotic 7y agoBrace initialization, I suppose.
- cjhanks 7y agoIt's bracket initialization of a struct, in this case the struct has no variables - the type is implicit from the method declaration.
- eMSF 7y agoWhile it makes no difference in this case, it's worth noting that Badge<T> is not an aggregate type because it has a user-provided constructor. Therefore the object is value initialized, i.e. the braces are equivalent to 'Badge<Device>()'. edit: what this means is that even if the struct had data members, you couldn't brace initialize it like an aggregate type, and to achieve something syntactically similar, you would need a suitable constructor.