Can somone help me?
I am trying to pass a function pointer to another class, but am running into difficulties. i cut out a lot of code, so tell me if I am missing something critica.
connection.hpp
connection_metadata{
public:
void setMessageCallback(std::function<void()> *message_callback){
m_message_callback = message_callback;
}
private:
std::function<void()> *m_message_callback;
};
data_stream.hpp
class data_stream{
public:
void init(){
//gets specific instance of connection class.
connection_metadata::ptr metadata = m_endpoint->get_metadata(m_connection_id);
//sets the callback function
metadata->setMessageCallback(&data_stream::message_callback);
}
void messageCallback(){
std::cout << "Test" << std::endl;
}
};
I however get the error:
Cannot initialize a parameter of type 'std::function<void ()> *' with an rvalue of type 'void (data_stream::*)()'
I can't figure out how to fix this, or even if I'm doing it right...