c++ Function Returns
Alas, after using Java compilers for so long now I made another ignorant assumption about c++. If you place your return value for your function inside any type of branching or looping structure make sure that at least one of the return statements can always be reached. If not you will have some major run-time errors that are hard to track down.
In this example when the 'hasName()' function returns false nothing is returned.
But in the case below, even if 'hasName()' is false, something is returned from the function.
Or as I've now learned to do. Turn On The Damn Compiler Warnings!
string SomeClass::getName() {
if(this->hasName())
return className;
}
In this example when the 'hasName()' function returns false nothing is returned.
But in the case below, even if 'hasName()' is false, something is returned from the function.
string SomeClass::getName() {
if(this->hasName())
return className;
else
return "";
}
Or as I've now learned to do. Turn On The Damn Compiler Warnings!