. Advertisement .
..3..
. Advertisement .
..4..
How to solve the problem – reference to non-static member function must be called? I have the sample detail:
void MyClass::buttonClickedEvent( int buttonId ) {
// I need to have an access to all members of MyClass's class
}
void MyClass::setEvent() {
void ( *func ) ( int );
func = buttonClickedEvent; // <-- Reference to non static member function must be called
}
setEvent();
While I was running it, I found the warning message:
Reference to non static member function must be called
That is my question in my midterm exam, and it is urgent. I searched the solutions for some websites, but I didn’t get it. I may miss any line or other changes. I appreciate your assistance!
The cause: The issue is that
buttonClickedEvent
is a member function, and calling it requires a pointer to a member.Solution:
Do this:
Then, in order to use it, you must have an object of type
MyClass
, such asthis
:You may want to have a look at https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-types, especially [33.1] Is the type of “pointer-to-member-function” different from “pointer-to-function”?