Im trying to refresh my c++ skills.. its been years and Im a little confused if this is OK or not.
I know you shouldn't return local variables, but I've seen this done before. Does the string class allocate its internal memory on the heap and so its ok.. thus returning just a pointer to the heap allocated object?
Thanks!Code:typedef std::string String; //Is this ok? why? String GetSomeString() { String ret; ret="bipbip"; return ret; } //How does this differ.. can this lead to any memory corruption? //If I just use the returned value as a check.. //if(GetSomeString=="bipbip").... String GetSomeString() { return "bipbip"; }
Adam