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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:57:56+00:00 2026-06-10T23:57:56+00:00

I’m trying to figure out why this code works (particularly the price part) struct

  • 0

I’m trying to figure out why this code works (particularly the “price” part)

struct CarType
{
    string maker;
    int year;
    float price;
    bool operator > (carType car)
    {
        if (price > car.price)
            return true;
        else return false;
    }
};

It says “we don’t nees a myCar.price, because myCar was the left operand”. What does that mean? I wrote this in another .h file:

bool operator > (Fraction a, Fraction b)
{
    if (a.numerator*b.denominator > b.numerator*a.denominator) return true;
    else return false;
}

See how I passed 2 Fraction structs? I’m not sure why the “myCar” only has to pass one CarType data struct or what the explanation means. Can someone please enlighten me? 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-10T23:57:57+00:00Added an answer on June 10, 2026 at 11:57 pm

    CarType is a struct. It contains information about a car. Assuming it has been initialized properly, it has set values for maker, year, and price.

    bool operator > (carType car) is a member operator of CarType. When the member operator > is called, it is called from/by the object on the left, just like a function would be. If you had a function inside CarType called myFunction, you would call it like this:

    myCar.myFunction();
    

    And it would operate on the data already set up inside myCar, right? It’s the same with operators. When you create the > operator for CarType, you call it like this:

    myCar > otherCar
    

    Probably with an if or something surrounding it, but the point stands. Since myCar is on the left of the > operator, it is the left operand. > is called on myCar, and otherCar is passed in as the right hand variable. The operators just make things look prettier; in this case, your > function is the same as if you’d written this function inside CarType:

    bool isGreaterThan (carType car)
    {
        if (price > car.price)
            return true;
        else return false;
    }
    

    And then this function would be called like this:

    myCar.isGreaterThan(otherCar);
    

    In this case it’s clear what’s going on, right? myCar is the object the function is being called on; otherCar is the car it’s being compared against. It’s similar when you use the operator; it’s implied that the left operand is calling the function, and the right operand is passed in. Overloading operators makes code simple and easy to read, and provides flexibility (ie. there are some data structures which would now perform sorts based on your > operator, which they couldn’t do if you decided to define equality with an isGreaterThan function.

    I hope this clears up your confusion; please let me know if there’s anything else you’d like me to explain!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.