I am studying data structure course and have been asked to create a sorted list, however I get an error whenever trying to declare a variable that use datatype. Here is what I have done so far
#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
};
However when compiling this I get an error:
$ 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;
The error is with this line List<int> x;
, isn't that how we are supposed to declare variables with templates?
Full code can be found here: https://pastebin.com/T2hXDxAP