- Aug 14, 2001
- 12,343
- 0
- 0
I'm using boost smart pointers specifically, but one thing I can't seem to figure out is how to have a function return "nothing".
e.g. normally you'd do something like:
Foo * find_a_foo() {
Foo * foo;
if((foo = look_for_a_foo_somehow())) return foo;
return NULL; // found nothing, now they can check the result of this function for truth and if this NULL is returned, it will evaluate to false
}
But with smart pointers:
shared_ptr<Foo> find_a_foo() {
shared_ptr<Foo> foo;
if((foo = look_for_a_foo_somehow())) return foo;
return ????; // what can I return to indicate "nothing"? "(shared_ptr<Foo>) 0" doesn't work, NULL doesn't work, tried a few other things as well..
}
e.g. normally you'd do something like:
Foo * find_a_foo() {
Foo * foo;
if((foo = look_for_a_foo_somehow())) return foo;
return NULL; // found nothing, now they can check the result of this function for truth and if this NULL is returned, it will evaluate to false
}
But with smart pointers:
shared_ptr<Foo> find_a_foo() {
shared_ptr<Foo> foo;
if((foo = look_for_a_foo_somehow())) return foo;
return ????; // what can I return to indicate "nothing"? "(shared_ptr<Foo>) 0" doesn't work, NULL doesn't work, tried a few other things as well..
}