I would like to write a function that apply a process to member of a class. The following code is working:
class AA
{
public:
AA(){};
~AA(){};
std::string type="AA";
};
class BB
{
public:
BB(){};
~BB(){};
template <typename T, typename TT>
void test(T& a, TT(T::*memberPtr))
{
std::cout<<"test: "<<(a.*memberPtr)<<std::endl;
}
std::string type="BB";
};
int main()
{
AA a;
BB b;
b.test(a, &AA::type);
}
But I know everything at compile-time so I am wondering if it is possible to write something equivalent but only with templates? So I could write something like:
b.test<&AA::type>(a);
that calls inside test(a):
std::cout<<"test: "<< (a.*MEMBER) <<std::endl; // MEMBER is given in template
or something like that.