将lambda分配给C ++中的变量

时间:2017-11-27 10:07:35

标签: c++ lambda

1

void(*f1)(int, float) = [](int, float){};
f1 = [](int, float){}; // OK.

2

auto f2 = [](int, float){};
f2 = [](int, float){}; // Error. Why?

错误讯息:

test.cpp:12:5: error: no match for ‘operator=’ (operand types are ‘main()::<lambda(int, float)>’ and ‘main()::<lambda(int, float)>’)
  f2 = [](int, float){};

3

auto f3 = [](int, float){};
auto f4 = f3;
f3 = f4; // Error.

错误讯息:

test.cpp:11:8: error: use of deleted function ‘main()::<lambda()>& main()::<lambda()>::operator=(const main()::<lambda()>&)’
     f0 = f1;

auto会怎样?

gcc(Ubuntu 5.4.0-6ubuntu1~16.04.5)5.4.0 20160609

clang version 3.8.0-2ubuntu4(tags / RELEASE_380 / final)

0 个答案:

没有答案