I understand that it’s illegal to return a reference to a temporary, but here’s my problem:
const stringSet & Target::dirList( const dirType type ) const
{
switch( type )
{
case SOURCE_DIR:
return m_sourceDirs;
case HEADER_DIR:
return m_headerDirs;
case RESOURCE_DIR:
return m_resourceDirs;
default:
return stringSet(); // PROBLEM HERE!
}
}
The three first three options return a const reference to a stringSet data member. What should I do for the default case? If I leave it out, the compiler (GCC with -Wall -Wextra -pedantic) complains and I don’t want it to because those options tend to catch my bed design choices in the most odd of ways 🙂
Thanks!
Keep a default set as a member too… and return a reference to it. That is of course if the default case is theoretically possible. If it is not, throw an exception and don’t return anything.