So for my latest assignment, I have been asked to convert our LinkedList and ListNode classes to template classes. I understand the general idea of templates, but all of the examples deal with more concrete examples. I'm having trouble extending it to my multi-file project with intermingled data types and classes.
Relevant, but incomplete, code shown.
linkedlist.h:
template< class T >
class LinkedList;
template< class T >
class ListNode
{
Day day;
ListNode* next; //ListNode* next;
ListNode(const Day &d, ListNode *n);
friend class LinkedList< T >;
}; // class ListNode
template< class T >
class LinkedList
{
ListNode< T > *head;
public:
LinkedList();
~LinkedList();
const Day& operator[](int index)const;
Day& operator[](int index);
T& operator+= (const Day &d);
T& operator-= (const Day &d);
}; // class LinkedList
linkedlist.cpp: (shown to ensure I understand general syntax)
template< class T >
ListNode< T >::ListNode(const Day &d, ListNode< T > *n): day(d), next(n)
{
} // ListNode()
template< class T >
LinkedList< T >::LinkedList():head(NULL)
{
} // LinkedList()
year.h:
class Year
{
int count;
LinkedList < class T > days; //This is the line that I think is causing all of my problems.
public:
Year():count(0){}
void addDate(int month, int day);
int findDate(int month, int day) const;
void read();
void searchDate(int month, int day) const;
void searchSubject(const char *s) const;
Year& operator+= (const Day &d);
Year& operator-= (const Day &d);
}; // class Year
year.cpp: (example function that uses days and generates error)
int Year::findDate(int month, int day) const
{
for(int i = 0; i < count; i++)
if(days[i].compareDate(month, day) == 0)
return i;
return count;
} // findDate()
Any help and understanding to the issue would be greatly appreciated.