I\'m still learning c++, so please bear with me. I\'m writing a simple wrapper around boost filesystem paths -- I\'m having strange issues with returning temporary strings.
CString c_str() const {
return mPath.string().c_str();
};
mPath.string()
returns a copy of a std::string
. That copy is stored in a temporary which will be destroyed at the end of this expression.
.c_str()
returns a pointer to memory which will be destroyed when the string is destroyed, i.e. at the end of this expression.
You are returning a pointer to memory which is already destroyed.