I'm having trouble with c++, trying to sort a playlist with my own functions but it is not working.. I checked many posts speaking about a possible similar problem but I couldn't find any solution. ( c++ - <unresolved overloaded function type> -- I'm having the same error as in this post but not sure to understand what to do then).
May I have a hint please? :) Here is my function to compare, comp just compare strings in lowercase.
bool Playlist::byTitleAscend (Music *a, Music *b) { return comp(a->getTitle(), b->getTitle()); }
Then I try to sort my list with it and it throws an error :/
_musics.sort(byTitleAscend); // ERROR, TODO: why ?
I hope it's clear enough!
In the documentation they use const & but it's also said that if we don't change the objects it's not necessary.
Error:
MusicReader/playlist.cpp:148: error: no matching function for call to 'std::list(Music*)::sort(unresolved overloaded function type)' _musics.sort(byTitleAscend);
I replaced < by ( because it was not showing.
_musics.sort(byTitleAscend);
line should be in Playlist class scope. If it is not, the line should be
_musics.sort(Playlist::byTitleAscend);
In fact there was several errors, @cokceken was right because I forgot to add the scope and the real problem was that I forgot to scope the comp function too ..
And then without putting the function as static it couldn't work neither, so thanks to @molbdnilo too !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.