#include <vector>
int main(){
std::vector<double> vec(100);
//...initialize it
double sum= [&vec]{
double sum{ 0 };
for (auto x : vec)
sum += x;
return sum;
};
}
I'm getting compiler error
no suitable conversion function from "lambda []double()->double" to "double" exists
I dont really understand this conversion problem. Even this isnt working and is giving me the same error double random_number = []{ returndouble{ 2 }; };
Both codes actually work even if i dont change them just put () after lambdas body.
When I read Stroustrups book he said that i dont even have to use parentheses if lambda doesnt take any arguments so the shortest lambda would be []{}, now turns out its []{}()?