Let's say I have a normalize function defined as:
Vec3f Vec3f::getNormalized() const { return (*this)/this->length(); }
Is it somehow possible to create a compile-time error if this function is used without something storing it's return value? ;
v.getNormalized(); // which most definitely is a typo
..instead of..
v = v.getNormalized();
In GCC, use -Wunused-result
to trigger the warning when a function's return value is ignored. And if you want an error instead of warning, use -Werror
to convert all warnings into errors. For more information see GCC Warning Options.
There does not seem to be an equivalent warning for the Visual C++ compiler. (If I am wrong, please edit this reply with the Visual C++ information.)
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