【发布时间】:2016-04-01 21:25:15
【问题描述】:
编译器告诉我断言失败,即使我在链接节点数组中至少有 2 个项目。如何修复这个 bool contains 函数?是的,我尝试了多种方法,但仍然遇到同样的错误。
请记住,数组的不同索引中有 2 个项目。但它没有在下面显示。
这是contain 函数:
bool Map::contains(string key){
bool idk = false;
if(elementsStoredCount != 0){
int idk = hashFunc(key); //the hashFunc computes using modulo
if(array[found] != nullptr){
idk = false;
}
else{
found = true;
}
}
return found;
}
当我在 main.cpp 中进行测试时,由于某种原因,第二行失败了。
assert(as.contains("1")==true);
【问题讨论】:
-
提供更多信息,例如:可编译代码、输入、你得到什么输出以及你期望什么等。
-
在这里猜测:obj 是否超出范围?这也是 C++11,而不仅仅是纯 C++
-
你的 hashFunc 是做什么的? idk 的值是多少?
-
看来错误在
hashFunc。 -
您如何知道该表包含您声称包含的内容?