Trying to pass a lambda to a constructor:
#include <functional> #include <exception> template<typename R> class Nisse { private: Nisse(Nisse const&) = delete; Nisse(Nisse&&) = delete; Nisse& operator=(Nisse const&) = delete; Nisse& operator=(Nisse&&) = delete; public: Nisse(std::function<R> const& func) {} }; int main() { Nisse<int> nisse([](){return 5;}); } When I compile I get an error message:
Test.cpp: In function ‘int main()’: Test.cpp:19:39: error: no matching function for call to ‘Nisse<int>::Nisse(main()::<lambda()>)’ Test.cpp:19:39: note: candidate is: Test.cpp:14:9: note: Nisse<R>::Nisse(const std::function<R>&) [with R = int] Test.cpp:14:9: note: no known conversion for argument 1 from ‘main()::<lambda()>’ to ‘const std::function<int>&’