未定义对运算符的引用!= 使用 std::unordered_set 时
Undefined reference to operator!= when using std::unordered_set
我一直在使用一组模板化函数contains
代码如下:
template<class V>
bool contains(const std::unordered_set<V>& c, const V& e)
{
return c.find(e) != c.cend();
}
我也有类似的标准::设置,标准::地图和标准::unordered_map
但是,我最近在使用它时遇到了链接错误:
CMakeFiles/dietAgent.dir/agent/workflow/autoscale/AutoscaleCoreScheduler
.cc.o : Dans la fonction « bool contains<WfNode*, WfNode*>
(std::unordered_set<WfNode*, std::hash<WfNode*>, std::equal_to<WfNode*>,
std::allocator<WfNode*> > const&, WfNode* const&) » :
/home/amxx/Work/Thesis/Code/diet/src/utils/stdext.hh:51 : référence
indéfinie vers « std::integral_constant<bool, true> operator!=
<std::__detail::_Node_const_iterator<WfNode*, true, false>,
std::__detail::_Node_const_iterator<WfNode*, true, false> >
(std::__detail::_Node_const_iterator<WfNode*, true, false> const&,
std::__detail::_Node_const_iterator<WfNode*, true, false> const&) »
我从错误中了解到的是,迭代器没有operator!=
......跆拳道?
更新:
显然,模板包装器不应该受到责备。我试过使用
if (mySet.find(value) != mySet.end()) { ... }
直接(而不是打电话给contains
(,我得到了同样的undefined referennce to operator!=
在你的类中,你需要重载运算符!=。
或者,您可以使用运算符 ==,如以下示例所示:
template<class V>
bool contains(const std::unordered_set<V>& c, const V& e)
{
return !(c.find(e) == c.cend());
}
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么 std::unique 不调用 std::sort?
- 是否可以<int>在一行中将向量值分配给 std::unordered<int,std::vector<int>>?
- unordered map -在c++ std::unordered_map中预分配桶