a template class has all static members replicated for each instanciation of it. If I want a static member that exists only once for all instanciations, what should I do? Use a normal static field outside of the class template? Would work, but seems unelegant since there is no more association to the template class. Is there a way to somehow associate such unique static member with a template class?
a template class has all static members replicated for each instanciation of it. If
Share
Nope. It has different statics for each specialization, but different specializations are different classes. Make no mistake about it,
vector<int>andvector<char>are totally separate. Think of it as writingIntVectorandCharVector.EDIT: Don’t use inheritance for this. Introducing a base class just so you can share a static member is definitely the wrong way to go.
If you want stuff shared between different classes, do it like you would usually do it. Wrap some statics in a third class and that’s it.