#include<iostream>
using namespace std;
int* New()
{
return new int(666);
}
int Foo()
{
//method1:
int* it = New();
return *it;
//method2:
return []() { return *(new int(666)); };//Complier has a complain here
/*Both New() and Lambda are callable object, are there any differences between method1 and method2?*/
}
int main()
{
cout << Foo() << endl;
return 0;
}
I'm fresh in C++, I encounter a situation above, I had review the chapter 10.3.2 to 10.3.3 of C++ Primer, where introduces the lambda expression.But it doesn't work for me, I'm also confused about the last annotation I list.
New. You didn't call the lambda. Also, C is not C++.