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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:12:10+00:00 2026-06-15T16:12:10+00:00

I have the following equals operator: bool operator==(const Duration& x, const Duration& y){ return

  • 0

I have the following equals operator:

  bool operator==(const Duration& x, const Duration& y){
        return ( x.hrs == y.hrs, x.mins == y.mins, x.secs == y.secs );
    }

I have also tried:

 bool operator==(const Duration& x, const Duration& y){
        return ( (x.hrs == y.hrs) && (x.mins == y.mins) && (x.secs == y.secs) );
    }

In my main method I have:

  //Arbitrary Durations - Testing
    Duration dTest0 (01,45,12);
    Duration dTest1 (01,35,45);
    Duration dTest2 (01,35,45);
    Duration dTest3 (01,25,05);

    if ( dTest0 == dTest1 ){
        cout<< "broken" << endl;
    }
    else{
        cout<< "working" << endl;
        }

My program keeps outputting “broken” which suggests that dTest0 and dTest1 are infact equal… Where am I going wrong?

Additional: If I use x.getHours == y.getHours... It puts a red line under the "." and says: ‘Error: a pointer to a bound function may only be used to call the function`.

Any advice would be appreciated. Thanks.

  • 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-15T16:12:12+00:00Added an answer on June 15, 2026 at 4:12 pm

    The first implementation will only return true if x.secs == y.secs. The results of the first two comparisons will be discarded. The , operator evaluates to the value of its second operand, which in this case boils down to just x.secs == y.secs.

    The second one, however, is correct. If it is not working, then you must be setting the values of hrs, mins, and secs incorrectly in the constructor of Duration.

    The problem that you have with getHours is that you need to call it. It is a member function after all. So do x.getHours() instead of x.getHours.

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

Sidebar

Related Questions

Basically, I have the following so far: class Foo { public override bool Equals(object
I have the following code: class Program { static void Main(string[] args) { Test
I have the following Groovy code snippet that is attempting to use operator overloading
I have a question about default = (equals) operator in F#. It allows to
quite often I have code like the following if (operator == Equal || operator
I have the following method and enum: public int GetRowType(string pk) { return Convert.ToInt32(pk.Substring(2,
I have the following @temp table : ------------------------------------ |Condition_ID Operator Order | | 1
Say I have a Point2 class, and I want to implement the following Equals:
I have following line of code in javascript: q && (c = q ===
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>

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.