Made type of function pointer:
typedef bool (*BreakFunc)(IReader *reader);
Some class has a method that takes a pointer to a function of type BreakFunc as a parameter. It looks like this:
GaugeReader::addBreakFunc(BreakFunc func);
In another class method, I call the addBreakFunc
function addBreakFunc
this:
CalibProcedure::setBreakpoints() { GaugeReader r; r.addBreakFunc([](IReader *reader){ return false; }); }
This code works without problems until the captured variables appear in the lambda. In this case, the compiler reports that it cannot find a suitable function addBreakFunc
. That is, the captured variables affected the lambda so much that it ceased to conform to the BreakFunc
type. Why did it happen? Are there other, more correct ways to force the addBreakFunc
method to take a lambda?
C ++ 11 is used. I am sure that the correct methods exist, since such functions are in the Qt library, for example, QtConcurrent::run(тут лямбда)
, but I did not find one that was needed in the heap of prototypes.
Maybe there are Qt tools to solve this problem?