Home > Back-end >  C lambda function does not perform, the result of the example program run
C lambda function does not perform, the result of the example program run

Time:05-18

#include
#include
#include

using namespace std;

Bool CMP (int a, int b)
{
Return a & lt; b;
}

Int main (int arg c, char * argv [])
{
QCoreApplication a (arg c, argv);

Vector Equivalent with {3, 2, 5, 7, 3, 2};
Vector Lbvec (equivalent);

Cout & lt; <"Lbvec: \ n";
For (int it: lbvec)
Cout & lt; Cout & lt;
Sort (equivalent. The begin (), equivalent. The end (), CMP);//the old practice
Cout & lt; <"Predicate function:" & lt; For (int it: equivalent)
Cout & lt; Cout & lt;
Sort (lbvec. The begin (), lbvec end (), [] (int a, int b) - & gt; Bool {return a & lt; b; });//Lambda expressions
Cout & lt; <"The lambda expression:" & lt; For (int it: lbvec)
Cout & lt;
Return a.e xec ();
}


The output is:
Lbvec:
3 2 5 7 3 2
Predicate function:
2, 2, 3, 3 5 7
Lambda expression:


Obviously no anonymous function called! The environment is ubuntu18.04 qtcreator4.11 g + + 9.3.0
Know the cause of the trouble to give directions!

CodePudding user response:

Try [=]

CodePudding user response:

Your code can be estimated is the output reason qt start blocking

CodePudding user response:

Turned out to be a.e xec () to blame!
  • Related