Since you mentioned that you were stuck in C ++ 03, the answer is that without changing the signature methodyou are stuck in some statictomfoolery:
, , lambda ++ 11 ( - const , void). , .
, :
template<class T, void(T::*PTR)()const, size_t I>
struct bind_member
{
typedef void(*fn_type)();
explicit bind_member(const T* _ptr)
{
ptr = _ptr;
}
static void func(void)
{
(ptr->*PTR)();
}
operator fn_type()
{
return &func;
}
private:
static const T* ptr;
};
template<class T, void(T::*PTR)()const, size_t I>
const T* bind_member<T, PTR, I>::ptr = NULL;
Live Demo
bind_member struct (template<class T, void(T::*PTR)()const, size_t I>)
T - , - . Myclassvoid(T::*PTR)()const const member T. PTRsize_t I , Myclass lambda , , , . ( , 0 /).
bind_member , . static.
func, , Myclass::m. m int, , func. , , .
:
bind_member C,
typedef void(*fn_type)();
operator fn_type()
{
return &func;
}
, func static, -. typedef func, void.
Myclass:
void run()
{
bind_member<Myclass, &Myclass::m, 0> b(this);
measure(b);
}
, , bind_member, this , bind_member (m). &Myclass::m , - , , , .
, b measure, .
++ 11 ( ), , , . measure , Myclass::m. , .