vendredi 28 décembre 2018

No matching function call error with usage of, lambda expressions and std::function.

I am trying to use this lambda expression in my code. And looks like something's wrong with definition of functor or lambda.

I believe the lambda expression is true. but I can't satisfy the prototype of function I defined.

Function definition:

    template<typename E, typename container> 
void for_each(Iterator<E,container> begin, std::function<void(E&)> fun)
{
    do // does the given unary functor to elements 
    {  //from starting iterator 'til the end.
        fun(*begin);
        begin = begin.next();
    }while(begin.hasNext());

    fun(*begin);
}

And caller:

  for_each(c.iterator(), [&](E& e){add(e);});

I except achieve this function call with lambda expression. But compiler says "error: no matching function for call to .."

Aucun commentaire:

Enregistrer un commentaire