3 ms·
T::T() = default; > You’d expect the printed result to be 0, right? You poor thing. Alas—it will be garbage. Some things can never be perfect, it seems. Here’s
by OptionOfT 2y ago
T::T() = default;
> You’d expect the printed result to be 0, right? You poor thing. Alas—it will be garbage. Some things can never be perfect, it seems. Here’s a relevant excerpt from our description of value-initialization:
Link: https://consteval.ca/2024/07/03/initialization/#:~:text=You%E2%80%99d%20expect%20the%20printed%20result%20to%20be%200%2C%20right%3F%20You%20poor%20thing.%20Alas%E2%80%94it%20will%20be%20garbage.%20Some%20things%20can%20never%20be%20perfect%2C%20it%20seems.%20Here%E2%80%99s%20a%20relevant%20excerpt%20from%20our%20description%20of%20value%2Dinitialization%3A https://consteval.ca/2024/07/03/initialization/#:~:text=You%...
That actually isn't that weird, because it would allow any consumer of your library to change how your library behaves.
- Twisol 2y agoThe alternative not making sense doesn't automatically make this solution make sense :( It just highlights how many corners C++ has backed its design into.