#include <iostream>
using namespace std;
int main()
{
auto f=[](int a,int b){return a+b;};
f(2,3);
int c=f;
return 0;
}
然后就提示出错了
---------- C++编译 ----------
2.cpp: In function 'int main()':
2.cpp:8:15: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
8 | int c=f;
| ^
2.cpp:6:16: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
6 | auto f=[](int a,int b){return a+b;};
| ^
2.cpp:6:16: note: no known conversion from 'int (*)(int, int)' to 'int'
输出完成 (耗时 1 秒) - 正常终止
using namespace std;
int main()
{
auto f=[](int a,int b){return a+b;};
f(2,3);
int c=f;
return 0;
}
然后就提示出错了
---------- C++编译 ----------
2.cpp: In function 'int main()':
2.cpp:8:15: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
8 | int c=f;
| ^
2.cpp:6:16: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
6 | auto f=[](int a,int b){return a+b;};
| ^
2.cpp:6:16: note: no known conversion from 'int (*)(int, int)' to 'int'
输出完成 (耗时 1 秒) - 正常终止

