我正在尝试使用github link https://github.com/efficient/cuckoofilter中的布谷鸟过滤器代码
每当我使用数据类型字符串时,它都会给出错误mycode:
cuckoofilter::CuckooFilter<string, 12> filter(total_items);但每次我运行代码时,都会出现这个错误
error: no match for call to ‘(const cuckoofilter::TwoIndependentMultiplyShift) (const std::_cxx11::basic_string&)’ 68 | const uint64_t hash = hasher(item); 在下面一行中
https://github.com/efficient/cuckoofilter/blob/master/src/cuckoofilter.h#L68
发布于 2020-07-05 03:24:50
在过滤器声明中,您使用了std::string类型;期望std::string成为template <typename ItemType, ...> class CuckooFilter { }中的ItemType
但是,散列函数TwoIndependentMultiplyShift需要uint64_t类型的密钥。该方法位于文件https://github.com/efficient/cuckoofilter/blob/master/src/hashutil.h中。
由于类型不匹配,会发生运行时错误。在旧的C++标准下,类型在编译时不受限制。因此,您不会看到任何编译时错误。
要解决您的问题,您可能必须使用支持std::string的散列函数或使用兼容的ItemType。
C++20引入了concepts来限制模板参数,这将有助于限制可用作模板参数的类型。这样,错误将在编译时变得明显。
https://stackoverflow.com/questions/62733210
复制相似问题