I need to use lists for my program, and I need to decide if I use std :: vector or std :: list. The problem with the vector is that there is no deletion method and with a list, that there is no operator []. Therefore, I decided to write my own class extending std :: list and overloading the [] operator.
My code is as follows:
#include <list> template <class T > class myList : public std::list<T> { public: T operator[](int index); T operator[](int & index); myList(void); ~myList(void); }; #include "myList.h" template<class T> myList<T>::myList(void): std::list<T>() {} template<class T> myList<T>::~myList(void) { std::list<T>::~list(); } template<class T> T myList<T>::operator[](int index) { int count = 0; std::list<T>::iterator itr = this->begin(); while(count != index)itr++; return *itr; } template<class T> T myList<T>::operator[](int & index) { int count = 0; std::list<T>::iterator itr = this->begin(); while(count != index)itr++; return *itr; }
I can compile it, but when I try to use it, I get a linker error. Any ideas?
c ++ list linker templates
Alexander Stolz Dec 14 '08 at 11:30 2008-12-14 11:30
source share