Is a explicit chaining acceptable?
class A {
public:
static const unsigned int id = 1;
};
class B {
public:
static const unsigned int id = A::id+1;
};
The advantage of this approach is that you always get the same Id and you know what it is no matter what your compiler is. While with __LINE__
or __COUNTER__
approach may not be so predicatable. The disadvantage is that with chaining your class must always know the previous one on the chain.
Playing with templates (and C++11):
template
class Identificable;
template <>
class Identificable<> {
public:
static const unsigned int id = 1;
};
template
class Identificable {
public:
static const unsigned int id = Prev::id+1;
};
class A : public Identificable<> {
public:
};
class B : public Identificable {
public:
};