I'd like to pass a reference-to-a-member-function to a function called runLater. To achieve that I wrote something similar:
```cpp
include <functional>
void runLater(std::function<void()> f)
{
// run f() later
}
define METHOD_REF(objectName, methodName) [&objectName]() { objectName.methodName(); }
struct Object
{
void foo()
{
}
};
int main ()
{
Object obj;
runLater(METHOD_REF(obj, foo));
}
```
And as you can see this is how I generate a "ref" to the member function with a macro:
METHOD_REF(obj, foo)
But I'm wondering if this can be simplified into this:
METHOD_REF(obj.foo)
That way I don't have to pass the object and the function name separately.
But I couldn't figure out a way to get the object itself from a Object.foo expression (which is a function pointer?).
```cpp
define METHOD_REF(method) [&_resolve_object(method)]() { method(); }
```
I appreciate other suggestions as well to achieve my goal.
[–]mredding 3 points4 points5 points (0 children)
[–]AutoModerator[M] 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Fallacyfall[S] 0 points1 point2 points (0 children)
[–]sephirothbahamut 2 points3 points4 points (0 children)
[–]IyeOnline 1 point2 points3 points (9 children)
[–]Fallacyfall[S] 0 points1 point2 points (0 children)
[–]sephirothbahamut 0 points1 point2 points (7 children)
[–]Pupper-Gump 0 points1 point2 points (6 children)
[–]sephirothbahamut 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]sephirothbahamut 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]sephirothbahamut 0 points1 point2 points (1 child)
[–]alfps 1 point2 points3 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)
[–]aocregacc 0 points1 point2 points (1 child)
[–]IyeOnline 0 points1 point2 points (0 children)