I have a class List which is a fixed size, linked List, and inside that class there is another class ListIterator which points to a specific element of that List. My problem is the c++ syntax I am not familiar with and the build errors from gcc are not helping me.
template<class T, int length>
class List {
public:
//some stuff here
//Row-struct
template<class T>
class ListIterator {
public:
ListIterator(int mPos, Row& mRow){pos = mPos; row = mRow;};
T& operator *();
private:
int pos;
Row& row;
};
typedef ListIterator<T> iterator;
iterator begin();
private:
int startIdx;
Row storage[length];
};
template<class T, int length>
ListIterator List<T, length>::begin() {
ListIterator *itor = new ListIterator(startIdx, storage[startIdx]);
return itor;
}
I get the following errors:
error: shadows template parm 'class T'
- How can I make this
typedef ListIterator<T>work? - How can I use the same
TI used forListfor the Iterator? - Why does my
begin()not work?
ìteratorinListIteratoras well as inListas typedefclass ListIteratorinsidetemplate <typename T> class Listhas access toT, it doesn't need to be a template. You could even directly name itclass iteratorand skip the typedef