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 8520997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:41:24+00:00 2026-06-11T06:41:24+00:00

I implemented a custom TimeStruct class, where I declare < operator as follows bool

  • 0

I implemented a custom TimeStruct class, where I declare < operator as follows

bool operator<(const TimeStruct t2) const;

implementation is as follows.

bool TimeStruct::operator<(const TimeStruct t2) const
{
//do something, I don't include the actual implementation
return true;
}

Then I have another class X where this TimeStruct class is a member, let’s call this member field Y. And I am using a vector, and I want to sort this vector on Y field of Class X. Therefore I will need to specify a method which might serve as a basis for the vector’s sort method.

Therefore I declared an additional method in X to compare different X’s.

bool compareX(const X& x1, const X& x2) const;

and the implementation is as follows:

bool X::compareX(const X& x1, const X& x2) const
{
return (x1.Y.operator<(x2.Y));
}

Unfortunately this code does not compile. I am receiving the following error.

No matching function call for TimeStruct::operator<(const TimeStruct&) const
candidates are : bool TimeStruct::operator<(TimeStruct&) const

I’ve been scratching my hair for the last hour, can anybody point out what I’ve been doing wrong.

  • 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-06-11T06:41:26+00:00Added an answer on June 11, 2026 at 6:41 am

    You need to pass by const reference in your TimeStruct operator:

    bool operator<(const TimeStruct& t2) const;
    

    and, according to the error message, you have provided

    bool operator<(TimeStruct&) const
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've implemented a custom IEqualityComparer for EventLogEntry. public class EventLogEntryListComparison : IEqualityComparer<List<EventLogEntry>>, IEqualityComparer<EventLogEntry> For
i've implemented this custom PHP Session Class for storing sessions into a MySQL database:
I have just implemented custom pagination by overriding the -(BOOL)knowsPageRange: and -(NSRect)rectForPage: methods. These
In my project, I've implemented custom i18n class that collects all untranslated strings during
I have implemented a custom OutputCacheProvider public class MongoDBCacheProvider : OutputCacheProvider, IDisposable { ...
I have implemented custom title bar feature using the following class CustomWindow . Other
I have implemented a custom designer class which inherits from DocumentDesigner. The standard Form
I have implemented custom class representing an enumeration possibilities similarily to this article :
I implemented a custom membership provider. I've also implemented my custom AES Encryption/Decryption overriding
I implemented a custom Profile object in code as described by Joel here: How

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.