Is There a Good Pattern for Creating a Unique Id based on a Type?
- by Michael Kelley
I have a template that creates a unique identifier for each type it is instanced. Here's a streamlined version of the template:
template <typename T>
class arType {
static const arType Id; // this will be unique for every instantiation of arType<>.
}
// Address of Id is used for identification.
#define PA_TYPE_TAG(T) (&arType<T >::Id)
This works when you have an executable made purely of static libraries. Unfortunately we're moving to an executable made up of dlls. Each dlls could potentially have its own copy of Id for a type.
One obvious solution is to explicitly instantiate all instances of arType. Unfortunately this is cumbersome, and I'd like to ask if anyone can propose a better solution?