将本地 CStringW 返回给调用者是否安全?
我有一个函数定义了一个在 CStringW 中键入的局部变量,通过值而不是通过引用将该对象返回给调用者是否安全?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

是的,应该没问题。
CString
内部使用带有引用计数的缓冲区并执行写入时复制,因此当您创建CString
的副本然后销毁原始对象时,一切都应该“只是工作”。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 ofCString
and then destroy the original object, everything should "just work".