I have a project in which I have to make a heterogeneous list of n containers, where n
will be given. The containers can be a list, queue or stack and each of them must implement a bool member(T const& x)
method, which checks if an object is present in the container. I also have to make an iterator for the heterogeneous list which can go through each element of all the containers(all the elements in the different containers will be of the same type).
My idea is to have an interface containing the member
method and 3 new classes each of them inheriting from the interface and the stl containers ( I know it's a bad idea, but I don't want to write my own list, queue and stack classes). As for the the heterogeneous list I thought of having a class with a data member which is a list or vector of the interface class.
The things I don't know how to do are: how do I inherit exactly from an stl container for a generic type T. Don't know if something like this can work:
template <typename T>
class MyList : public list<T>, CommonInterface
Also the biggest problem I have is how to make the iterator for the heterogeneous list, so that it can traverse thought all elements of the containers. My idea is to transfer all the elements to one vector object, and use it's iterator (a kind of wrapping I guess).
Any ideas and solutions on this problem are welcomed. If there is something unclear about the question, I'll try to clarify it as soon as possible.