Question: I need to use lists for my program and needed to decide if I use std::vector or std::list.
The problem with vector is that there is no remove method and with list that there is no operator []. So I decided to write my own class extending std::list and overloading the [] operator.

My code looks like this:

```
#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 I get a linker error if I try to use it. Any ideas?

Answer: 
All template code should be put in header file. This fill fix linking problems (that's the simplest way).
The reason it happens is because compilers compiles every source (.cc) file separately from other files. On the other hand it needs to know what code exactly it needs to create (i.e. what is the T in template is substituted with), and it has no other way to know it unless the programmer tells it explicitly or includes all the code when template instantiation happens. I.e. when mylist.cc is compiled, it knows nothing about mylist users and what code needs to be created. On the other hand if listuser.cc is compiled, and all the mylist code is present, the compiler creates needed mylist code. You can read more about it in [here](http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm) or in Stroustrup.

Your code has problems, what if user requests negative or too large (more than amount of elements in the list). And i didn't look too much.

Besides, i don't know how u plan to use it, but your operator[] is O(N) time, which will probably easily lead to O(N\*N) loops...
In addition to other excellent comments, the best way to extend a standard container is not by derivation, but writing free functions. For instance, see how [Boost String Algorithms](http://www.boost.org/doc/libs/1_37_0/doc/html/string_algo.html) can be used to extend `std::string` and other string classes.