Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:34:01+00:00 2026-05-26T05:34:01+00:00

I have a struct named Recipes.h and a vector called vector<Recipes> recipes . The

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:34:02+00:00Added an answer on May 26, 2026 at 5:34 am

    From the very short snip of code you posted, it can be seen that you use recipes first as an object and then as a type. Your comparison function probably wants as parameters Recipes > const& instead. Note that if the operation does not depend on the Menu class it would be better to declare this function as a static member function.

    The function signature should be:

    static bool Menu::compare(const Recipes& lhs, const Recipes& rhs)
    

    and you would then use it like this:

    sort(recipes.begin(),recipes.end(),compare); ...or...
    sort(recipes.begin(),recipes.end(),&Menu::compare);
    

    Both last statements are the same, I think the later is more explicit about compare.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a struct ABC to contain an int ID, string NAME, string
I have a struct defined as: struct { char name[32]; int size; int start;
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int
I have this struct: struct Map { public int Size; public Map ( int
I have a struct named Game with an array of levels, defined like this:
I have the following code: int main(void) { struct { int x; } a,
I have a C++ object, Graph , which contains a property named cat of
I have a struct which takes 3 named parameters in to the constructor... public
I have put all the structures in a header file named structure.h : struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.