my question is about how to template\'ize the name of a class member that should be used.
Maybe a simplified & pseudo example:
sellibitze's solution is fine (though to be honest not very: see my edit), only it limits you to using only members of type int. A more general solution would be this (although the member is NOT a template parameter here)
#include
struct MyClass
{
int i;
char c;
};
template
void DoSomething(std::vector& all, T MyClass::* MemPtr)
{
for(std::vector::size_type i = 0; i < all.size(); ++i)
(all[i].*MemPtr)++;
}
int main()
{
std::vector all;
DoSomething(all, &MyClass::i);
DoSomething(all, &MyClass::c);
}
EDIT: Also please note that it is not generally a good idea for a pointer to member to be a template parameter inasmuch as only such pointers that are known compile-time can be passed, that is you can't determine the pointer runtime and then pass it as a template param.