I need to call a non static member function from a static member function of the same class.
The static function is a callback. It can receive only void as data, though which i pass a char*. So i cannot directly provide the class instance to the callback. I can pass a structure instead of char to the callback function. Can anyone give eg code to use the non static member function in a static member function . and use the structure in the static member function to use the instance of the class to call the non static member function?
C++ – How to call a non static member function from a static member function without passing class instance
cclassstaticstruct
Related Topic
- Python – How to print instances of a class using print()
- C++ – Static constant string (class member)
- Java – Why are static variables considered evil
- C++ – The static keyword and its various uses in C++
- C# – System.Windows.Application.GetResourceStream returns null
- Php – How to limit items from for loop
- C++ – Why can a const member function modify a static data member
Best Answer
Normally such a callback would look like this:
Of course, you need to make sure, data points to an instance of your class. E.g.
Now, if I understand you correctly, you need to also pass a char*. You can either wrap both in a struct and unwrap it in the callback like so:
or, if you can modify the definition of CMyClass, put all the necessary data in class members, so that you can use a callback as in the first example.