Search code examples
c++visual-c++mfccstring

Is it safe to return local CStringW to the caller?


I have a function defined a local variable typed in CStringW, is it safe to return this object to the caller by value, not by reference?


Solution

  • Yes, it should be ok. CString internally uses a buffer with reference counting and does copy-on-write, so that when you create a copy of CString and then destroy the original object, everything should "just work".