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: 
Depending on your needs, you should use `std::vector` (if you need often appends/removes at the end, and random access), or `std::deque` (if you need often appends/removes at the end or at the beginning, and your dataset is huge, and still want random access). Here is a good picture showing you how to make the decision:

[![Container Choice](https://i.stack.imgur.com/qWf2C.png)](https://i.stack.imgur.com/qWf2C.png)  

(source: [adrinael.net](http://adrinael.net/containerchoice.png))
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.