c++ - Saving an anonymous function (lambda) as function-typed variable -


I'm using an anonymous function (also known as lambda), obviously I have a special I can create a square, but C + 11 says that I can use an anonymous function for this. However, to readability and understand, I decided to save the anonymous function in a local variable typed as a function. Unfortunately, I get an error:

  There is no match to call (std :: function & lt; bool (point *, point *)); (Point * & Amp;) Note: The candidate is: Note: _Res std :: function & lt; _Res (_ArgTypes ...) & gt; :: operator () (_ ArgTypes ...) const [with _Res = bool; _ArgTypes = {Point *, Point *}] Note: Candidates expect 2 arguments, 1 provided  

What am I doing wrong? The so-called candidate is Greek for me, I tried to give Lumbda a place through direct search, but he did not work either.

  #include & lt; Vector & gt; #include & lt; Function & gt; # Include & lt; Algorithm & gt; Using Std :: vector; Using the Std :: function; Using Std :: find_if; Point * Path :: getPoint (int x, int y) {function & lt; Bool (Point *, Point *) & gt; HowToFind = [& amp; X, & y] (Point * A, Point * B) - & gt; Bull {if (a-> getX () == x} {back true; } And if (a-> getX ()  getX ()) {back true; } Other {return false; }}; Vector and lieutenant; Point * & gt; :: Iterator found Ya = find_if (this-> points.begin (), this-> points.end (), howToFind); If (foundYa == points.end ()) {return nullptr; } Return * found; }  


The correct part of the code after the useful answer of Senator I had to refact my code at other places, but it is beyond the scope of this question:

  function & lt; Bool (point *)> HowToFind = [& amp; X, & y] (Point * A) - & gt; Bull {if (a == nullptr) {return false; } And (if (a-> getX () == x & amp; a-> getY () == y) {true;} other {return false;}}};   

According to the function should be unaryPredicate , i.e. Should have a single logic.

  Template> Class Input This, Class UnaryPredicate> InputIt find_if (Input first, InputIt last, UnaryPredicate q);  

Comments