I have a function that needs to return NULL in some cases and there is another function that needs to test for the return value of this function. I am aware of boost::optional but am not sure how to use the syntax.
Below would be a simple example of said usage:
int funct1(const string& key) {
// use iterator to look for key in a map
if(iterator == map.end()) {
return NULL // need help here!
else
return it->second;
}
void funct2(string key) {
if(funct1(key) == NULL) { // <-- need help here!
// do something
} else {
// do something else
}
Can someone please help with the syntax?
Thanks.
It stays in the “
NULL” state until you set it. You can use this idiom:Then: