The code below compiles fine, until I uncomment the line: lambda();. Why does it compile if I don't use the function relying on the default argument, but when I try to use the default argument, it doesn't compile anymore?
#include <iostream> int main() { static auto lambdaDefaultParameter = []() // must be static, otherwise I get the error that a local variable can't be a default parameter { std::cout << "default\n"; }; // trying a lambda that takes another lambda as parameter auto lambda = [](auto&& f = lambdaDefaultParameter) { f(); }; lambda([]() {std::cout << "test\n"; }); // ok //lambda(); // error } https://stackoverflow.com/questions/66773298/error-passing-a-lambda-as-default-argument March 24, 2021 at 08:54AM
没有评论:
发表评论