【发布时间】:2019-07-31 13:35:52
【问题描述】:
我有一个函数,我使用 struct 作为std::map 的键。但我不确定如果我退出我的函数,该结构会发生什么。将存储在std::map 中,还是在退出功能范围时被删除,std::map 中的进一步搜索使用将被破坏?
//Map is standard class
class Map { ... }
//hashmap of maps
std::map<Point, Map*> maps;
void Maps::addMap(Map *map, int row, int column) {
Point point = {row, column};
maps[point] = map;
}
编辑:
感谢托马斯·萨布里克
我知道像 int 这样的基本类型会被复制,但我不知道 struct 会发生什么。如果被复制,那么我是安全的
编辑 2
我改变了我的问题,我不知道该问什么才能得到我的答案,对不起。
【问题讨论】:
-
这是一本可以帮助你的好书:akrzemi1.wordpress.com/2012/02/03/value-semantics
-
什么是
maps?请尝试创建minimal reproducible example 向我们展示。或许也刷新how to ask good questions 和this question checklist。 -
什么是地图?和点?和地图?
-
point被复制。你可以在这里阅读大部分内容en.cppreference.com/w/cpp/container/map/operator_at -
谢谢,如果被复制了,我就安全了,这就是我需要知道的。非常感谢