You cannot pass pure names because the names are not part of the C ++ metamodel, but you can pass member pointers to your function:
template <typename TYPE, typename T> bool MyFunction(TYPE obj, T TYPE::*mp)
Here's how you could use it in a small, complete program:
struct Type1{ unsigned int Field1; unsigned int Field2; }; struct Type2{ unsigned int Field2; unsigned int Field3; }; int main() { Type1 t1; Type2 t2; MyFunction(t1, &Type1::Field1); MyFunction(t2, &Type2::Field3); }
And here is a living example .
Andy prowl
source share