3

1.

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

2.

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

Error Message:

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.

Error Message:

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

What happens to auto?

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

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

chaosink
  • 1,329
  • 13
  • 27
  • Please be more specific than "error". You must have seen some error messages that you can share. – molbdnilo Nov 27 '17 at 10:22
  • BTW: Both those compilers are pretty old. A recent g++ says "note: a lambda closure type has a deleted copy assignment operator". – molbdnilo Nov 27 '17 at 10:26

0 Answers0