fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct test
  4. {
  5. template<typename type>
  6. void method1(type func){func();}
  7. void method2(){
  8. int y=2;
  9. method1([&](){cout<<x<<y<<endl;});
  10. }
  11. int x=1;
  12. };
  13.  
  14. int main() {
  15. test t;
  16. t.method2();
  17. return 0;
  18. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
12