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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:24+00:00 2026-05-23T03:57:24+00:00

I have to compare(>,<,==) two class object based upon different criteria, explained below. class

  • 0

I have to compare(>,<,==) two class object based upon different criteria, explained below.

class Student
{
    int iRollNumber;
    int iSection;
    int iMarks;
}
  1. I want to do comparison with iRollNumber, iSection, iMarks (Independently).
  2. I want to do comparison with iRollNumber, iSection (Combined).
  3. I want to do comparison with iMarks, iSection (Combined).
  4. ……….

Currently I am achieving this with GetMethods() and comparing them using if elseif elseif.. structure.

This is leading to the messy code everywhere!

If I use operator overloading I have to decide on one way of comparison.

Please suggest a way to do it with elegant coding.

Or

Can it be possible to call operator overloading Polymorphically?

  • 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-23T03:57:25+00:00Added an answer on May 23, 2026 at 3:57 am

    Write named functions:

    int CompareR( const Student & a, const Student & b );
    int CompareS( const Student & a, const Student & b );
    int CompareM( const Student & a, const Student & b );
    int CompareRS( const Student & a, const Student & b );
    int CompareMS( const Student & a, const Student & b );
    

    although the need to do so many different kinds of comparison on a class is a bit unusual – you normally only need one or perhaps two. The functions should return the same kind of values as strcmp() does:

    <  returns -1
    == returns 0
    >  returns 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two decimal values in Java script. I have two
I would like to compare two dates in javascript. I have been doing some
Are there any tools to effectively compare two XML schema's? I have seen some
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two models as follows: class Tag(models.Model): # ... class Paragraph(models.Model): tags =
Does a comparison sort have to compare the A[i] largest and A[i+1] largest values?
I have 2 strings that I'd like to compare, and return the positions of
I have 2 arrays of 16 elements (chars) that I need to compare and
I have an integer field in a ClientDataSet and I need to compare to
I have a HashMap relating Keys to Strings, and I need to compare some

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.