Is it possible to bind the "this" pointer
-
Hi, Is it possible to bind the "this" pointer to make a callback into a non-static class member function (c++98, no boost). I don't think the "this" pointer is passed directly as a parameter to the function?
typedef void (*CallBackType)(void);
...
obj->SetCallback(std::bind1st(&MyClass::CallBackFunc, this));
-
Hi, Is it possible to bind the "this" pointer to make a callback into a non-static class member function (c++98, no boost). I don't think the "this" pointer is passed directly as a parameter to the function?
typedef void (*CallBackType)(void);
...
obj->SetCallback(std::bind1st(&MyClass::CallBackFunc, this));
No, it is not possible (at least as far as I know). From
bind1st
atC++ Reference
:Return function object with first parameter bound This function constructs an unary function object from the binary function object op by binding its first parameter to the fixed value x.
A method taking one argument is not exactly a binary function.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
Hi, Is it possible to bind the "this" pointer to make a callback into a non-static class member function (c++98, no boost). I don't think the "this" pointer is passed directly as a parameter to the function?
typedef void (*CallBackType)(void);
...
obj->SetCallback(std::bind1st(&MyClass::CallBackFunc, this));
You could use bind1st if CallBackFunc took one parameter:
void CallBackFunc(int) { ... }
...
obj->SetCallback(std::bind1st(std::mem_fun(&MyClass::CallBackFunc), this));Since it takes nothing, you may have to write your own function template that takes a callable and a pointer that returns a small function object that stores the callable and the pointer as members and invokes them with operator(): as always, by refusing to use boost you're forcing yourself to reimplement parts of it.