我有一个简单的代码片段,其中尝试使用std::destroy_at()
释放内存:
#include <iostream>
#include <memory>
using namespace std;
class base
{
public:
~base()
{
cout << "des" << endl;
}
};
int main()
{
{
base* b1 = new base();
std::destroy_at(b1); // destructor is executed for b1 object (but memory is not freed for b1)
}
return 0;
}
有人能指导我如何使用destroy_at()
来释放内存吗?原始数据类型也观察到相同的行为。使用最新的VS2017编译器。
std::destroy_at
不会释放内存。 - James Picone