lundi 6 mars 2017

Is the C++ expression for_each(v, [](string x){}) syntactically correct?

Is the below expression valid for for_each()?

    for_each(v,[](string x){
    cout<<x<<endl;
});

Ref: http://ift.tt/2n6YvjC

The above expression throws an error:

error: no matching function for call to ‘for_each(std::vector >&, main()::)’ }); ^ In file included from /usr/include/c++/5/algorithm:62:0, from test.cpp:4: /usr/include/c++/5/bits/stl_algo.h:3761:5: note: candidate: template _Funct std::for_each(_IIter, _IIter, _Funct) for_each(_InputIterator __first, _InputIterator __last, _Function __f) ^ /usr/include/c++/5/bits/stl_algo.h:3761:5: note: template argument deduction/substitution failed: test.cpp:60:6: note: deduced conflicting types for parameter ‘_IIter’ (‘std::vector >’ and ‘main()::’) });

Aucun commentaire:

Enregistrer un commentaire