9
I have a C++ struct and a method:
struct Account
{
unsigned int id;
string username;
...
};
Account GetAccountById(unsigned int id) const { }
I can return an Account struct if the account exists, but what to do if there's no account?
I thought of having:
- An "is valid" flag on the struct (so an empty one can be returned, with that set to false)
- An additional "is valid" pointer (const string &id, int *is_ok) that's set if the output is valid
- Returning an Account* instead, and returning either a pointer to a struct, or NULL if it doesn't exist?
Is there a best way of doing this?