通过c ++中的make pair将结构添加到映射[关闭]

问题描述 投票:0回答:1

我正在尝试添加此对,其中entiticountdto是字符串标题,字符串体裁和int的结构,但我得到:C ++没有重载函数的实例与参数列表匹配。有什么想法吗?

struct EntityCountDTO {
    std::string title;
    std::string genre;
    int count = 0;
};


for (const auto& m : v) {
    if (mapa.find(m.getGenre()) == mapa.end()) {
        mapa.insert(make_pair<string, EntityCountDTO>(m.getGenre(), EntityCountDTO{ m.getTitle(), m.getGenre(), 0 }));
    }
    else{
        mapa.find(m.getGenre())->second.count++;
    }
}
c++ c++11 stdmap
1个回答
0
投票

您可以使用std::map::emplace在适当位置构造元素:

std::map::emplace
© www.soinside.com 2019 - 2024. All rights reserved.