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

  • Home
  • SEARCH
  • 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 7561083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:04:42+00:00 2026-05-30T13:04:42+00:00

I hope this is not painfully obvious. I am getting this cryptic error :

  • 0

I hope this is not painfully obvious. I am getting this cryptic error :

fold.cpp:92: error: expected primary-expression before ‘)’ token

The line that it is referring to is:

if (binary_search (corpus.begin(),corpus.end(), left, customArray::operator<(customArray)))

I arrived at this error after using the simpler call:

if (binary_search (corpus.begin(),corpus.end(), left))

and getting this error message (the important part is the note at the end, saying to change it to the above call)

In function ‘bool std::binary_search(_ForwardIterator, _ForwardIterator, const _Tp&)     [with _ForwardIterator = std::_List_iterator<customArray>, _Tp = std::string [3]]’:
fold.cpp:92:   instantiated from here
/usr/include/c++/4.2.1/bits/stl_algo.h:4240: error: no match for ‘operator<’ in ‘__val <    __i. std::_List_iterator<_Tp>::operator* [with _Tp = customArray]()’
/usr/include/c++/4.2.1/bits/stl_algo.h: In function ‘_ForwardIterator   std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator =   std::_List_iterator<customArray>, _Tp = std::string [3]]’:
/usr/include/c++/4.2.1/bits/stl_algo.h:4239:   instantiated from ‘bool    std::binary_search(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator =   std::_List_iterator<customArray>, _Tp = std::string [3]]’
fold.cpp:92:   instantiated from here
/usr/include/c++/4.2.1/bits/stl_algo.h:2906: error: no match for ‘operator<’ in   ‘__middle. std::_List_iterator<_Tp>::operator* [with _Tp = customArray]() < __val’
fold.cpp:16: note: candidates are: bool customArray::operator<(customArray)

Essentially, I am trying to use a binary search on a linked list of custom (array type) objects. The rest of the relavent code is here:

// here is the custom class I am using in the list
class customArray
{
public:

  // this is a somewhat lame way to compare, but it seems to work
  bool operator< (customArray temp)
  {
    return array[0] < temp.array[0];
  }

 bool operator> (customArray temp)
  {
    return array[0] > temp.array[0];
  }

  bool operator== (customArray temp)
  {
    return ((array[0] == temp.array[0]) && (array[1] == temp.array[1]) && (array[2] == temp.array[2]));
  }

  string array[3];
};

//All of this stuff is in main

customArray one;
//some processing here to fill one
corpus.push_back (one);

// sort the list 
corpus.sort();
corpus.unique();

string left [3];

if (binary_search (corpus.begin(),corpus.end(), left, customArray::operator<(customArray)))
{

}

I hope this is easy to understand. Let me know if there is any way that I can clarify.

  • 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-30T13:04:44+00:00Added an answer on May 30, 2026 at 1:04 pm

    Your first error message was because binary_search uses < on the iterators, but list’s iterators don’t support <. This error has nothing to do with whether or not you pass a comparison function as an argument to binary_search.

    Your second error message is because you specified the type when passing the function as an argument. That’s basically the same as calling a function as f(int x) instead of f(x), which is syntactically incorrect. It should just be customArray::operator<. However, as I said before, that won’t help you because you’ll just get the first error message again.

    Basically you can’t perform a binary search on a linked list.

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

Sidebar

Related Questions

This has been driving me nuts. I hope it's not been asked before but
I hope this has not been covered before, but if I compile a 32-bit
Hope this is not a dupe. I would like to be able to do
I hope this question does not come off as broad as it may seem
I hope this question is not considered too basic for this forum, but we'll
I hope this question is not a RTFM one. I am trying to write
I hope this question is not 'controversial' - I'm just basically asking - has
I hope this question is not a duplicate but I didn't find anything equivalent
How can I do this? (The following code does NOT work, but I hope
I hope this is not a duplicate of a question, but I have three

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.