1

Why would the following lambda not adhere to the signature when adding a capture element?

[&callback](unsigned handle, void* userData, void* data, unsigned size) -> void { ... }

but this would?

[](unsigned handle, void* userData, void* data, unsigned size) -> void { ... }

Signature:

typedef void (*em_async_wget2_data_onload_func)(unsigned, void*, void*, unsigned);
Jan de Jager
  • 870
  • 2
  • 13
  • 35

2 Answers2

7

Lambdas with captures can not be simply converted to function pointers. For maximum flexibility (but not performance) consider the use of std::function<void(unsigned,void*,void*,unsigned)>

TartanLlama
  • 63,752
  • 13
  • 157
  • 193
jepio
  • 2,276
  • 1
  • 11
  • 16
3

Only captureless lambdas can be converted to a pointer to a function.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621