std::unordered_map<std::string, std::shared_ptr<AbstractEdgeFindCategories>> algorithmCategories;增加元素
时间: 2024-09-15 11:10:25 浏览: 62
在C++中,如果你想在std::unordered_map<std::string, std::shared_ptr<AbstractEdgeFindCategories>>
这样的无序关联数组(也称为哈希表)中添加元素,你可以像下面这样操作:
// 假设已经有一个实现了AbstractEdgeFindCategories接口的对象ptrEdgeCategory
std::shared_ptr<AbstractEdgeFindCategories> ptrNewCategory = createNewEdgeFindCategory();
// 使用键(字符串)作为索引,如果键不存在则自动创建新的桶并添加键值对
algorithmCategories["category_name"] = ptrNewCategory;
// 或者,如果你确定键不存在,可以直接插入:
if (algorithmCategories.find("category_name") == algorithmCategories.end()) {
algorithmCategories["category_name"] = ptrNewCategory;
}
这里,createNewEdgeFindCategory()
是一个自定义函数用于生成新的AbstractEdgeFindCategories
类型的指针。
相关推荐







