Re: How to get the absolute address of an object's member function?
On May 12, 8:42 am, blackbiscuit <infozyzh...@gmail.com> wrote:
Dear all,
Suppose I have a class A which is defined as follows.
class A
{
public:
void f( int i )
{
}
};
A a;
How to get the absolute address of a.f( int )? Thank you very much!
Here is our member functor object with 1 parameter that will show you
the syntax for passing, storing and calling a member function:
class Task { public: virtual void execute() = 0; };
template<class C, class F, class P1>
class MethodTask1 : public Task
{
public:
C* m_c; F m_f; P1 m_p1;
MethodTask1(C* c, F f, P1 p1) : m_c(c), m_f(f), m_p1(p1) {}
virtual void execute() { (m_c->*m_f)(m_p1); }
};
template<class C, class F, class P1>
Task* buildMethodTask(C* c, F f, P1 p1) { return new MethodTask1<C, F,
P1>, c, f, p1); }
// called like this:
A a = ...;
Task* task = buildMethodTask(&a, &A::f, 43);
task->execute();
delete(task);
(The real one uses smart pointers, but you get the idea)
Enjoy,
Andrew.
--
Andrew Tomazos <andrew@tomazos.com> <http://www.tomazos.com>