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: 
Given your original problem statement,

> 
> 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 [].
> 
> 
> 

there is no need to create your own list class (this is not a wise design choice anyway, because `std::list` does not have a virtual destructor, which is a strong indication that it is not intended to be used as a base class).

You can still achieve what you want using `std::vector` and the `std::remove` function. If `v` is a `std::vector<T>`, then to remove the value `value`, you can simply write:

```
#include <vector>
#include <algorithm>
T value = ...; // whatever
v.erase(std::remove(v.begin(), v.end(), value), v.end());

```
The obvious stuff has already been described in details:  

But the methods you choose to implement??

* Destructor.
	+ Not required compiler will generate that for you.
* The two different versions of operator[] are pointless
	+ Also you should be uisng std::list::size\_type as the index
	+ Unless you intend to support negative indexes.
* There are no const versions of operator[]
* If you are going to implement [] you should also do at()
* You missed out all the different ways of constructing a list.
* Containers should define several types internally
	+ see <http://www.sgi.com/tech/stl/Container.html>