Here is a possible way to do it using __LINE__
macro and templates:
template <int>
struct Inc
{
enum { value = 0 };
};
template <int index>
struct Id
{
enum { value = Id<index - 1>::value + Inc<index - 1>::value };
};
template <>
struct Id<0>
{
enum { value = 0 };
};
#define CLASS_DECLARATION(Class) \
template <> \
struct Inc<__LINE__> \
{ \
enum { value = 1 }; \
}; \
\
struct Class \
{ \
enum { id = Id<__LINE__>::value }; \
private:
Example of using:
CLASS_DECLARATION(A)
// ...
};
CLASS_DECLARATION(B)
// ...
};
CLASS_DECLARATION(C)
// ...
};
See live example.