dimanche 28 janvier 2018

C++ lambda to std::function error with non const strings

The following line gives error in c++ 11:

function<bool(string,string)> comp = [] (string& s1, string& s2) {return s1.length() > s2.length(); };

but this does not:

function<bool(string,string)> comp = [] (const string& s1, const string& s2) {return s1.length() > s2.length(); };

The second call has const in parameters. Any explanation?

Aucun commentaire:

Enregistrer un commentaire