the function don't have return and no parameters.
error:
"conversion from '<unresolved overloaded function type>' to non-scalar type 'std::function<void()>' requested"
#include <functional>
class ClassDerived
{
public:
void MouseClick()
{
// ...
}
};
void test1(ClassDerived *clsPointer)
{
// Stores a member function.
std::function<void(ClassDerived&)> func = &ClassDerived::MouseClick;
// An object is necessary when calling the function.
func(*clsPointer);
}
void test2(ClassDerived *clsPointer)
{
// Stores a lambda that calls a member function on the object.
std::function<void()> func = [clsPointer]{ clsPointer->MouseClick(); };
// No object needs to be passed in because it's all handled by the lambda.
// Note that the object pointed to by the pointer that was captured by the
// lambda still needs to be valid at this point.
func();
}