My Herb Schildt book on C++ says: \"... In C++, if a function is declared as returning a value, it must return a value.\" However, if I write a function wit
It's not mandatory to have a return statement in a function declared as returning non-void and it doesn't have to lead to undefined behaviour.
Such a function could:
std::terminateOf course, if a function avoids undefined behaviour by always doing one of the above it probably shouldn't be declared as returning non-void if possible.
One obvious case where it would need to is if it is a virtual function which for a particular point in a class hierarchy can't return a valid value and always exits via an exception.