Good all the time of day! I want to implement a kind of Callback. I want the method of one class to call a method of another class. Functions outside the classes, described and implemented outside the classes, and the function main () has succeeded in calling, but with the methods of the classes it does not work. I am writing this function declaration in the Foo
class to call the Child
function: void foo(void(Child::*pFunc)(int));
But this entry is incorrect. Can someone write the correct definition or give a link? Thank you in advance!
- oneYes, everything seems to be right. Let me try to guess where the error occurs: when a function is called via this pointer. - skegg
- @mikillskegg, no, I had exactly the Qt Creator error issued during function declaration. He emphasized this method with a red line. There was a problem in syntax. But in general, you are right. I tried to call a function without an object. - Lucky_spirit
|
1 answer
Look here: https://stackoverflow.com/questions/1738313/c-using-class-method-as-a-function-pointer-type There in a post from Michael Burr it seems that you need to write something.
Here's another: https://stackoverflow.com/questions/1485983/calling-c-class-methods-via-a-function-pointer
- oneI solved the problem. It was necessary to make a forward declaration of the required class and pass a pointer or a reference to an object of the class Child to the method. - Lucky_spirit
|