The problem here is that a member function expects a "hidden" first argument that is a this pointer. Loosely speaking, a member function
void Func(int a, double b);
is equivalent to a free function
void Func(MyClass* this, int a, double b);
There is no way to pass a this pointer via ClassicFuncPtr, and std::function tricks won't help you here. target() doesn't do any magic, it just returns a pointer to the stored function if types match, and in your code they don't, that's why you get a null pointer. std::bind returns a functional object (that stores this inside), but a functional object is quite distinct from a function pointer and can't be converted into one.
Given that you can't change the callback type, there is a pretty ugly and fragile work-around that uses a static variable to store the value of this pointer. It should give you the idea of how to make it work, at least in principle.
class MyClass {
public:
void Test() {
thisPtr = this;
CallMyFunc(MemberFuncInvoker);
}
private:
inline static MyClass* thisPtr;
static void MemberFuncInvoker(int a, double b) {
thisPtr->MemberFunc(a, b);
}
void MemberFunc(int a, double b) {
std::cout << "a = " << a << ", b = " << b << '\n';
}
};
Note that static member functions don't expect a hidden this argument and behave like free functions in this respect (due to the absence of this argument, you can't access non-static data members inside a static member function).
Demo
Typically, callbacks are accompanied with a void*-like parameter that can be used to pass a this pointer. For example, theEnumWindows function from WinAPI has the signature
BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam);
That lParam is passed to a callback
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
Then, inside a free (or static) callback function you could do:
reinterpret_cast<MyClass*>(lParam)->MyMemberFunction(hwnd);
MemberFunctionastaticmember function, and pass a pointer to it directly? Unless it's really using other members of the object, because then there's really no way to do it using the information you have provided.MemberFunctionexpects athispointer. How are you going to pass it, even in principle?