为什么 std::list<string> 有效,但 std::list <int>不起作用
Why does std::list<string> work but not std::list<int>
我在Ubuntu上实现AVL树时使用模板。
当我写template class AVLTree<std::list<int> >;
时,该文件将无法编译,它告诉我:
未定义引用 'AVLTree <std::__cxx11::list><std::__cxx11:::basic_string><char,>, std::allocator >, std::allocator <std::__cxx11::basic_string><char,> , std::allocator >>>>::insert(std::__cxx11::basic_string <char,>char_traits , std::allocator >('
而且我不明白它没有参考的内容。
但是当我写template class AVLTree<std::list<string> >;
时,它的编译效果很好
我需要AVLTree
存储存储字符串值的链表。
为什么一个编译而另一个不编译?如何解决我的问题?
PS:我已经包含了<list>
,<string>
和<iostream>
,以及我自己的头文件。
仔细检查错误消息表明链接器找不到AVLTree::insert(string)
方法。
根据您发布的稀疏信息,我最好的假设是您将以下行中的模板参数从 list<string>
更改为 list<int>
:
template class AVLTree<std::list<string>>;
这行代码显式告知编译器使用 list<string>
作为模板参数实例化 AVLTree 模板的版本。因此,当您尝试在更改后编译代码时,它会为您提供错误消息,指出它找不到AVLTree::insert(string)
函数,因为编译器现在正在为list<int>
生成代码。
您的程序包含引用 AVLTree<list<string>>
的其他代码。至少,您还必须更新该代码才能使用list<int>
。
简化为可以在此站点上发布代码的内容,那么您将在此过程中发现问题,或者至少会改变以获得一个好的答案。
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- C++中带有List类的迭代器Segfault
- 使用"std::unordereded_map"映射到"std::list"对象
- 呼叫运营商<<临时
- GCC对可能有效的代码抛出init list生存期警告
- 使用std::list创建循环链表
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 重载Singly Linked List中的赋值运算符
- <<操作员在下面的行中工作
- '[](std::list& list)<int>{return std::move(list)}(list)' 是否保证将 'list' 留空?
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- "std::list::splice(std::const_iterator pos, std::list&& other)"是否保证将"其他"留空?
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- QStringList vs list<shared_ptr<QString>> 性能比较C++
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改