lambda表达式

//lambda表达式
    //[]:必须存在不能省略,空表示没有参数
    //=表示作用于该模块的所有局部变量(值传递)(推荐)
    //&表示作用于该模块的所有局部变量(引用传递)
    //this 可以使用在lambda表达式类中的成员变量
    [作用域](参数)mutable->返回类型{};
     QPushButton *button=new QPushButton;
//        [=](){
//        button->setText("Button111");
//    };只表示函数声明   加入下面的()才表示调用
     [=](){
     button->setText("Button111");
     }();

     [button](){//值传递
     //只能修改该表达式外面的button,外面其他的变量等不可访问
     button->setText("Button111");
     }();
     [&button](){//引用传递
     //只能修改该表达式外面的button,外面其他的变量等不可访问
     button->setText("Button111");
     }();

 //()表示参数,如果没有参数可以不写,(a,b)或(&a,&b)
     //mutable:按值传递时加上该关键字可实现:可以修改按值传递进来的拷贝但不修改值本事
     QPushButton *button1=new QPushButton;
     QPushButton *button2=new QPushButton;
     button2->move(100,100);
     button1->setParent(this);
     button2->setParent(this);
     int m=10;
     connect(button1,&QPushButton::clicked,this,[m]()mutable{m+=100;qDebug()<,当返回void或者return只有一个时可以省略
     int re=[]()->int{return 1000;}();
     qDebug()<

你可能感兴趣的:(java,前端,服务器)