I am trying to create a template class which contains a static list of objects which there is only one of. What i have so far works but it gives me a copy of "mylist" for each different type of class B parameter. How can i change it so that i get one "mylist" for all instantiations of class B regardless of template parameters?
This is what i have:
template <class T> class A {
...
};
template <class T> class B {
static list<A<T> > mylist;
...
};
template <class T> list< A<T> > B<T>::mylist;
Thanks in advance :)
template<class T> class Foo;, each instance ofFoo<T>for differentTs is a completely different type. Consequently, ifFoo<>contains a static data member, each instance ofFoo<T>for differentTs will contain a different static data member. To have one data member that can contain different types, look at Boost.Variant if all types are known beforehand, or Boost.Any otherwise. (But really, your design sounds highly questionable in the first place.)