Is There a Good Pattern for Creating a Unique Id based on a Type?
Posted
by Michael Kelley
on Stack Overflow
See other posts from Stack Overflow
or by Michael Kelley
Published on 2010-03-16T20:49:27Z
Indexed on
2010/03/16
20:51 UTC
Read the original article
Hit count: 263
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?
© Stack Overflow or respective owner