c++ - 如何删除C++中的变量

标签 c++ visual-studio visual-c++ types

我想在我的程序中释放内存。

虽然我是新手,但我非常关心性能。

string i_want_to_delete_this = "I don't want this cleared, but            
completely gone";
/* I figured out */ i_want_to_delete_this.clear() /* simply sets the
string value to "". I want to be able to do this with every
datatype! I want it completely gone, not even declared anymore. */

最佳答案

我不明白你为什么要这样做,并且在任何情况下你都不能删除或以其他方式删除命名变量,除非它们在概念上由编译器在它们超出范围时为你删除,并且当包含它们的函数退出时实际上被删除。例如:

{
   {
       string i_want_to_delete_this = "I don't want this cleared, but            
completely gone";
   }     // it's gone
}

关于c++ - 如何删除C++中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41598011/

相关文章:

c++ - 函数 undefined reference C++

visual-studio - 找不到扩展。请确保已安装扩展

c++ - 奇怪的默认构造函数语法

C++ Lambda 函数闭包 - 内存问题

c++ - 是否允许实现将两个相同的函数定义放置在同一地址,或者不允许?

c# - BackgroundWorker 循环中的方法更新进度条

c++ - Qt 5.4 静态构建在 Visual Studio 2013 中产生 "unresolved external symbol"链接错误

WinAPI C++ 客户端在读取之前检测匿名管道上的写入

c++ - 错误 C2661 : no overloaded function takes 2 arguments

c++ - 在构造函数初始化程序中确定数组大小