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.


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;
  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()


class Year
  int count;
  LinkedList < class T > days;   //This is the line that I think is causing all of my problems.
  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.

So I just realized that I have to #include linkedlist.cpp when other files are going to be using the templates. =]

This question has already been answered. Start a new discussion instead.