i.e. this should be ok:
Object obj("param");
but this should not:
Object("param");
Is there a way to prevent the second scenario from being done?
You can use the nodiscard attribute for a type (with C++17 or later).
struct [[nodiscard]] Object {};
auto main() -> int {
Object{}; // error
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With