I have a struct named Recipes.h and a vector called vector<Recipes> recipes. The vector contains 1 int, and 2 strings in each element (a string chef name and a string called instructions). However I want to sort the whole vector ONLY by the string chef_name. I tried doing something like this
sort(recipes.begin(),recipes.end(),compare);
bool Menu::compare(const recipes* lhs, const recipes* rhs)
But it says recipes is not a type name. How do I go about sorting this vector?
From the very short snip of code you posted, it can be seen that you use
recipesfirst as an object and then as a type. Your comparison function probably wants as parametersRecipes > const&instead. Note that if the operation does not depend on theMenuclass it would be better to declare this function as astaticmember function.The function signature should be:
and you would then use it like this:
Both last statements are the same, I think the later is more explicit about
compare.