Original Post
Dear Thread reader, I had an idea about a class that will allow me to call member functions like they where normal functions. I'm not at my development pc right now so I can't really test this but I tough that maybe one of you guys knows if this might work. Here is a sample: Now my question is, will this work or do I have to do some secret assembly magic? I have a general idea of how that will work. Just pop all arguments (including the this pointer) and then call the function address. But of course it would be nicer if this worked. I will check it out as soon as I get to my dev pc. Ow and I'm using linux so I would compile this with g++. Tjaalie, [Edited by - Tjaalie on August 19, 2009 8:55:02 AM]
typedef int (*memfunct)(void* _this, int argument);
class member_function
{
public:
member_function(void* _class, memfunct funct)
{
m_class = _class;
m_funct = funct;
}
int call(int argument)
{
return m_funct(m_class, argument);
}
private:
void* m_class;
memfunct m_funct;
};
class A
{
public:
int do(int argument)
{
std::cout << argument;
return argument+1;
}
}
int main()
{
A aclass;
member_function afunction(&aclass, (memfunct)A::do);
afunction.call(15);
return 0;
}