You cannot return a link to a temporary object created on the stack. I will be destroyed by the time your function returns, and your application will crash.
If you are going to do something like this, you will have to return by value, not by reference, i.e.
stringSet Target::dirList( const dirType type ) const
This, obviously, can have performance implications, as you will most likely end up with a copy creator called for your other links. An alternative would be to avoid creating a temporary object on the stack. Depending on your application, there are several ways to do this, for example, to have a simple pool from which you get your temporary objects, which are collected at some point in the garbage, or you could use dirList for the stringSet argument, which is filled in according to your functions.
Best case - don't you just have a constant default? Do I need to be unique for every call?
source share