jeudi 22 janvier 2015

How can I get the class of a member function pointer?

Consider the code:



class Character
{
void kill();
void send_to_wall();
}

template <typename T>
void GeorgeFunc(T fp)
{
??? obj;
(obj.*fp)();
}

int main()
{
GeorgeFunc(&Character::kill);
}


So my question here is: how can I get ???? It seems that the compiler definitely knows what this type is (Character) during template instantiation, but I'm not sure how to get at it. My current workaround is to change to: void GeorgeFunc(void (T::*fp)()), but it would be cleaner to simply get the type from the member function pointer. decltype(fp) would return void(Character::*)(), and decltype(fp()) would return void. Any way to get Character?


Aucun commentaire:

Enregistrer un commentaire