samedi 5 décembre 2020

no viable conversion from 'function

I am trying to create a lambda function that will apply a particular transformation to a linked list. in order to prepare the conversion function, I tried making this function but I am getting the following error no viable conversion from 'function<char (std::string &)>' to 'function<void (std::__cxx11::basic_string)> at line link_list firstChar = list.map(first_char); I am pasting the code below for reference.


link_list<T> map(std::function<link_list<T>(char &l)> fprint)
    {
        std::ignore =fprint;
    };

 std::function<char(std::string&)> first_char = [](std::string &st) {
        if (st.length() > 0) {
            return st.at(0);
        } else {
            return char(0);
        }
    };

    link_list<char> firstChar = list.map(first_char);
    firstChar.print();

Aucun commentaire:

Enregistrer un commentaire