Void func (int) {
STD: : cout & lt; <"In func";
}
Void test (void func (*) (int)) {
Func (1);
}
Int main () {
The test ([] (int a) {STD: : cout & lt; <"Lambda" & lt; }
How to set up the parameter, make the test () function accepts the lambda function, more than a & amp; , can introduce external variables:
Int main () {
Int b=9;
The test ([& amp;] {(int a) STD: : cout & lt; <"Lambda" & lt;}
CodePudding user response:
It is your turn to a lambda expressions to a function pointer, rule is allowed, but the transformation of the lambda there cannot be caughtCodePudding user response:
# include & lt; Iostream>
using namespace std;
Void funcx (int) {
STD: : cout & lt; <"Func" In & lt;}
Template
Void test func (F) {
Func (1);
}
Int main () {
Int b=10;
The test (funcx);
The test ([& amp;] {(int a) STD: : cout & lt; <"Lambda" & lt;}