C++ 变量销毁 [英] C++ Variable destruction

查看:107
本文介绍了C++ 变量销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个:

std::wstring str = std::to_wstring(100);
str = std::to_wstring(1000); // Is the previous str destroyed?

如果我将局部变量重新分配给另一个变量,旧的会被破坏吗?

If I reassign the local variable to another variable, is the old one destroyed?

推荐答案

之前的str被破坏了吗?

是的.你分享的代码片段没有内存管理,都是自动存储.

Yes. There is no memory management happening in the code snippet you shared, it's all automatic storage.

这篇关于C++ 变量销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆