【发布时间】:2015-12-01 13:50:35
【问题描述】:
我有一张地图:
std::map<std::string, MyDataContainer>
MyDataContainer 是一些class 或struct(没关系)。现在我想创建一个新的数据容器。假设我想使用可用的默认构造函数:
// This is valid, MyDataContainer doesn't need constructor arguments
MyDataConstructor example;
// The map definition
std::map<std::string, MyDataContainer> map;
std::string name("entry");
// This copies value of `example`
map[name] = example;
// Below, I want to create entry without copy:
std::string name2 = "nocopy"
// This is pseudo-syntax
map.createEmptyEntry(name2);
有没有办法做到这一点?当我只想在地图中初始化它时跳过创建辅助变量?是否可以使用构造函数参数来做到这一点?
【问题讨论】:
标签: stdvector stdlist c++ c++11 std stdmap