I am working with lambdas for the first time. I am supposed to write a function walk() which takes a lambda function as a parameter.
In the header I declared said function as:
template<class T>
void walk(T operation) const;
We are supposed to define the function in an .inl, which I have done like this:
template<class T>
void Sea::Grid2D<T>::walk(T operation) const{
for(auto a : Sea::Grid2D<T>::grid){
operation(a);
}
}
My question comes in at this point, since we are given a test class, which calls our walk() function like this.
grid.walk([&](int const &cell) { sum += cell; });
This call of the walk function results in the following error:
error: cannot convert 'testWalkAndFilter()::<lambda(const int&)>' to 'int'
43 | grid.walk([&](int const &cell) { sum += cell; });
How would I go about converting my lambda function into the int or needed parameter?
While trying to solve this problem. I've also tried to give the walk function a reference, or a const reference parameter, but nothing has worked so far.
TinSea::Grid2D<T>and theTinT operationsupposed to always be the same type? Currently, you're forcing them to be the same.