'm using a lambda expression to specialize a class that I don't want to sub-class, but I'm having difficulty in compiling certain expressions, and the error messages are not useful. The code that reproduces the compilation problem is the following:#include <iostream>#include <functional>using namespace std;class M{public: function<int (int r, int c)> fun; M() { fun = [=] (int r, int c) -> int { return r * 2 + c; }; }};void foo(M * A){ int test1 = A->fun(1,1); cout << test1 << "\n"; auto f1 = [=]() { int test = A->fun(2,2); cout << test << "\n"; }; f1(); int * a = (int*)malloc(sizeof(int)); auto f2 = [=] () { *a = 2; }; f2(); cout << *a << "\n"; //auto f3 = // [=] () // { // int test = A->fun(3,3); // cout << test << "\n"; // *a = test; // }; //f3();}int main(){ M * A = new M(); foo(A); return 0;}The code as it is shown compiles and works fine. The problem occurs when I try to uncomment the block of code defining f3 and making the call to it.This code illustrates the problem because in the definition of f1 and f2, those lambda expressions and calls work fine, but when combined, the expression does not compile.I'm using Visual Studio 11 C++ Beta on Windows 7 x64. I haven't tried this yet on the just-released Release Preview.
Visual Studio/Team Foundation Server/.NET Framework Tooling Version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...