Passing Bound Functions to Events in CPP

Hi,

I am re-creating some code in c++.
I have had some problems with converting code involving events & callbacks. Specifically, I want to register a function to a button.pressed callback. However, I cannot figure out how to pass a method attached to an object into the callback.

The intellisense suggests I need to pass in a “void (*callback)()”, which I believe is just a pointer to a function with no arguments and no return value.

However, when I try to pass in a parameter-less and return-less function that is associated with a class, it fails because its associated with the class. I understand that the object itself acts a hidden parameter of some sort, but I would have thought that calling the function from within the class would sidestep this issue.

#include "vex.h"

using namespace vex;

class temp
{
private:
public:
    temp();
    void functionIWantToRegister();
};



temp::temp() {
    Controller1.ButtonA.pressed(functionIWantToRegister); 
    // Error: argument of type "void (temp::*)()" is incompatible with parameter of type "void (*)()"
}

void temp::functionIWantToRegister() {
    printf("do stuff every time event is called");
}

I have attempted to find another way to get around this by using lambda functions or std::function, but none of these are able to get to the type “void (*callback)()” (so that I can use the builtin VEX event system). Is there any way to go about passing in bound functions to the events, or do I need to make my own event system?
(or any other general recommendations for resolving this issue)

Thanks, Phoenix

You can only pass static class member functions to an event handler.
http://p-nand-q.com/programming/cplusplus/using_member_functions_with_c_function_pointers.html

It’s far easier in Python.