当试图让const_iterator查找元素是否存在于集合中时,得到编译错误
Getting compilation error while trying to get const_iterator to find the element exist in the set or not
template <class T>
Node<T>* LinkedList<T>::findCommonNode_hash(LinkedList<T>* list_2)
{
unordered_set<Node<T>*>* set = new unordered_set<Node<T>*>();
Node<T>* curr_list_1 = head->next;
Node<T>* curr_list_2 = list_2->head->next;
unordered_set<Node<T>*>::const_iterator itr = set->find(curr_list_1);
if(itr == set->end())
{
set->insert(curr_list_1);
}
else
return curr_list_1;
unordered_set<Node<T>*>::const_iterator itr1 = set->find(curr_list_2);
if((itr1 == set->end()))
{
set->insert(curr_list_2);
}
else
return curr_list_2;
return nullptr;
}
IDE:代码块c++ 11。当试图获得const_iterator来查找元素是否存在于集合中时,我得到了下面的错误。
C:EducationDataStructure_AlgorithmsListList.cpp|252|
error: need 'typename' before 'std::unordered_set<Node<T>*>::
const_iterator' because 'std::unordered_set<Node<T>*>' is a dependent scope|
错误信息提示您必须添加typename
关键字,因为在这种情况下const_iterator
是一个依赖名称。
:
typename unordered_set<Node<T>*>::const_iterator itr = set->find(curr_list_1);
当然,其他类似的行也是如此。
无论如何,你的代码似乎没有任何意义,但我猜那是因为它只是在进行中的工作。
相关文章:
- 尝试使用集合函数时出现分段错误
- 在尝试使用递归查找集合子集的总数时,我遇到了分割错误
- 集合布局上的 Qt 分割错误
- 从 C++ 中的集合中擦除时出现分段错误
- 创建集合向量作为类成员会在 c++ 中给出错误
- C++ 分段错误 - 具有集合的结构列表
- 为什么此C 代码不起作用 - 试图删除集合中的元素时,请参考错误
- CMAKE GOOGLETEST在集合集合中会重新定义错误
- 在集合中转换为小写 C++ 错误 C2664
- 在声明'const'函数中循环访问具有'const_iterator'的集合会导致错误
- 将配对插入集合时编译错误
- 集合上的C++/CX属性引发错误
- 集合并集的编译错误
- 插入集合时出现分段错误
- 收到此错误时如何实现非托管线程安全集合: <mutex> 使用 /clr 编译时不支持
- 在stl集合中移除迭代器时出现分割错误
- Java JNI: c++中原始(双精度)数组集合中的错误值
- 在集合中使用嵌套类时出现不完整的类型错误
- 贪心算法错误使用c++集合
- 当试图让const_iterator查找元素是否存在于集合中时,得到编译错误