C 中的排序列表
Sorted lists in C++
我正在研究数据结构课程,并已被要求创建一个排序的列表,但是,每当试图声明使用数据类型的变量时,我会遇到错误。这是我到目前为止所做的
#include<iostream>
using namespace std;
int main(){
List<int> x;
// Other Code for testing
}
const int MAX_ITEMS = 30;
template<class T>
class List{
private:
int size;
int currIndex;
T data[MAX_ITEMS];
public:
// list functions
};
但是,在编译此问题时,我会收到一个错误:
$ g++ sortedList.cpp
sortedList.cpp:5:3: error: use of undeclared identifier 'List'
List<int> x;
^
sortedList.cpp:5:11: error: expected '(' for function-style cast or type
construction
List<int> x;
错误是在此行List<int> x;
上,这不是我们应该如何用模板声明变量吗?
可以在此处找到完整的代码:https://pastebin.com/t2hxdxap
假设您是编译器。您正在从上到下读取文件,然后遇到以下内容:
List<int> x;
编译器看到了这一点时,它会进行:
wtf!我从未见过。是标识符吗?让我检查...不!在
main
或main
之前什么都没有!随机的胡言乱语?是的,让我们创建一个错误!
因此,编译器会产生错误。要解决此问题,您需要在main
之前定义类。(您无法转发该类是一个模板,在使用之前需要定义更多信息,请在此处找到更多信息(。
相关文章:
- 试图在c++中对数字列表进行排序
- 在STL - C++中按成绩对学生列表进行排序?
- 使用列表 STL 递归进行插入排序
- 列表 iter 不取消引用 使用列表进行插入排序
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- 如何按键对 std::对列表进行排序?
- 如何通过保持第一个插入的位置来对列表中插入的其余元素进行排序?
- 如何使用cpp编写选择排序算法以降序对元素列表进行排序?
- 使用自定义比较函数在类内进行列表排序
- 列表::排序更改值C
- 对于列表排序,有没有办法使用相同的参数让多个运算符重载?
- 在 c++ 中将数字从列表排序到数组中的气泡排序问题
- 运算符<用于列表排序
- C++列表排序功能
- C++ STL 算法(列表排序)OpenMP/多线程实现
- 列表排序不正确
- 列表排序和结构体向量排序之间的性能差距.c++
- 对抽象数据类型的stl::列表排序
- C++std列表排序使用自定义比较器,该比较器依赖于对象实例的成员变量