can function return 0 as reference
Posted
by helloWorld
on Stack Overflow
See other posts from Stack Overflow
or by helloWorld
Published on 2010-06-17T09:49:47Z
Indexed on
2010/06/17
9:53 UTC
Read the original article
Hit count: 126
c++
I have this snippet of the code
Account& Company::findAccount(int id){
for(list<Account>::const_iterator i = listOfAccounts.begin(); i != listOfAccounts.end(); ++i){
if(i->nID == id){
return *i;
}
}
return 0;
}
Is this right way to return 0 if I didn't find appropriate account? cause I receive an error:
no match for 'operator!' in '!((Company*)this)->Company::findAccount(id)'
I use it this way:
if(!(findAccount(id))){
throw "hey";
}
thanks in advance
© Stack Overflow or respective owner