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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:11:14+00:00 2026-05-23T23:11:14+00:00

In a question regarding the use of typeid is C++, I suggested it could

  • 0

In a question regarding the use of typeid is C++, I suggested it could be used to compare types in objects comparison. I haven’t seen it done much, but I had Java’s equals in mind.

Looking into Java a bit more, this seems to be the case: Some say the actual classes of the two objects should be compared, and some say instanceof is the right tool to use, possibly with double dispatch. There are of course cases in which one of the two is definitively more suitable, but at least both options are considered.

In C++, OTOH, I could barely find code in which the actual types are compared. On most cases, double dispatch is used (with dynamic_cast), and I couldn’t find anyone insisting a quick type comparison is the right thing to do at the beginning of the equality check.

I’m wondering why the problem of polymorphic type comparison has two acceptable solutions in Java, while in C++ only one seems to be considered the best practice? Are there significant technical differences, or just different approaches?

Note: My claims are based on impression, not concrete knowledge. If they are wrong and Java and C++ are indeed similar in that aspect – or different for reasons other than the above, it will obviously be an acceptable answer.

  • 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-23T23:11:15+00:00Added an answer on May 23, 2026 at 11:11 pm

    In Java, all types ultimately derive from Object, and Object
    defines a virtual function Object.equals(Object other), so you
    can compare anything with anything else, regardless of whether
    it makes sense or not. In C++, there is no univeral base, and
    there is no implicit definition of ==. == is normally only
    overridden when it makes sense, for comparing objects of the
    same type, and the compiler will complain if you write nonsense
    code. In cases where there is an inheritance hierarchy, it is,
    of course, up to the author to decide whether == makes sense
    (I usually doesn’t, but there are a lot of exceptions), and if
    so, what it should mean with respect to comparing objects of
    different types. Within the hierarchy, or outside of it: it
    might make sense to support == between BigInteger and
    BigFloat, for example, even if the classes aren’t related by
    inheritance.

    The reason you don’t see the problem discussed much in C++ is,
    of course, because you don’t define == unless there’s some
    logical meaning for it, and then you define it according to the
    logical meaning. In Java, you generally have to define equals
    regardless, so you have to “invent” some meaning, and you get
    discussion over what the invented meaning should be.

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

Sidebar

Related Questions

I got a question regarding content types and their IDs and how to use
I have a question regarding how to use the formula property to be used
I have a question regarding use of FFT. Using function getBand(int i) with Minim
I have question regarding the use of function parameters. In the past I have
I have a very general question regarding the use of LINQ vs SQL to
I have a question regarding VB.net and the use of rsData connections to an
I have a (dump) question regarding VB/C# I often use third party classes where
I have a question regarding a problem with L2S, Autogenerated DataContext and the use
Developing for Android 2.3, I have a question regarding layouts. I use a vertival
I've got a quick question regarding the use of repositories. But the best way

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.