gpt4 book ai didi

c++ - 标准 :map Destructor call Key Destructors as well as Value Destructors?

转载 作者:太空狗 更新时间:2023-10-29 20:13:52 26 4
gpt4 key购买 nike

例如,下面是否泄漏?

Foo ( )
{
std:map<std:string, int> myMap;
myMap[std::string("Bar")] = 2983;
}

我相信它不会泄漏,但找不到关于这一点的具体文档。

最佳答案

是的,映射析构函数 map::~map() 将为它管理的每个键和值调用析构函数并释放内存。

§ 23.2.1 表 96 — 容器要求(续)

(&a)->X() void 
the destructor is applied to every element of a; all the memory is deallocated.

关于c++ - 标准 :map Destructor call Key Destructors as well as Value Destructors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19157946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com