That is not possible, you have to resort to either macro-based solutions or use a predefined set of types that provide named members.
A possible macro-based approach:
#define MAGIC(name_) \
template<typename T> struct Magic1 { \
T name_; \
};
MAGIC(foo);
or:
#define MAGIC(type_, name_) \
struct Magic1 { \
type_ name_; \
};
MAGIC(foo);
Using preprocessor magic, e.g. utilizing Boost.Preprocessor, you should be able to generate n named members in a more convenient way.
Another approach might be using a predefined set of classes providing certain named members from that you inherit:
enum { MemberNameFoo, MemberNameBar };
template<class T, int id>
struct named_member;
template<class T>
struct named_member<T, MemberNameFoo> {
T foo;
};
template<class T>
struct named_member<T, MemberNameBar> {
T bar;
};
// holder for the above, just one member for this example:
template<class T, int name>
struct holder : named_member<T, name> {};
// using it:
typedef holder<int, MemberNameFoo> HasFoo;
typedef holder<int, MemberNameBar> HasBar;
Using compile-time lists you could then inherit from n named_member
instantiations, Boost.MPL could help here.