the code I posted was simply a contrived example. a more typical usage might be:
Code:
class database
{
class table
{ };
table &
retrieve_table_1( string const & name )
{
/*
if found, return a reference to the table.
otherwise, return null.
*/
}
bool
retrieve_table_2( string const & name, table & result )
{
/*
if found, result is valid and return true.
otherwise, return false.
*/
}
table *
retrieve_table_3( string const & name )
{
/*
if found, return a pointer to the table.
otherwise, return NULL.
*/
}
};
given the choice, I would choose to use the function retrieve_table_1 because it has a more simple interface. moreover, since it's clear that the table may not exist there wouln't be any confusion about the need to check for a null reference.