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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:28:25+00:00 2026-05-24T12:28:25+00:00

I have a set of polymorphic C++ classes and they are all instantiated by

  • 0

I have a set of polymorphic C++ classes and they are all instantiated by the same module (Windows DLL). Now having two pointers to such classes and having called typeid:

SomeCommonBase* first = ...; //valid pointer
SomeCommonBase* second = ...; //valid pointer
const type_info& firstInfo = typeid( first );
const type_info& secondInfo = typeid( second );

can I compare retrieved type_info addresses

if( &firstInfo == &secondInfo ) {
   //objects are of the same class
} else {
   //objects are of different classes
}

or use ==

if( firstInfo == secondInfo ) {
   //objects are of the same class
} else {
   //objects are of different classes
}

to detect whether objects are of (exactly) the same class or of different classes? Is it guaranteed to work when objects are instantiated from within the same module?

  • 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-24T12:28:26+00:00Added an answer on May 24, 2026 at 12:28 pm

    As I’m writing this, your code is

    SomeCommonBase* first = ...; //valid pointer
    SomeCommonBase* second = ...; //valid pointer
    type_info& firstInfo = typeid( first );
    type_info& secondInfo = typeid( second );
    

    It should not compile because typeid returns a reference to const.

    Worse, you are asking for type info about the pointers. Both pointers are of type SomeCommonBase*, so you’re guaranteed that they are of the same type. Ask instead for type info about the pointed to objects.

    That said, as @DeadMg remarked, you also need to use operator== to compare type info objects.

    The C++ standard does not address the issue of dynamic libraries. But within any given Windows module you should be safe.

    Cheers & hth.,

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

Sidebar

Related Questions

I have set up Tapestry 5 project and all went fine, until I deployed
I have a number of class, all with exactly the same interface. This interface
I have the following classes: class Person { public string Name { get; set;
I want to have a set of interchangeable classes to perform operations on a
I have some problems to set up and association correctly, I looked at all
I have set a cookie (in Javascript) at: www.sampledomain.com but when I go to
I have set up a JTable and have made it to contain 18 columns.
We have set the following app settings to be iPhone only, but in the
I have set up a connection with a rather large https server and I
I have set up push notifications successfully on my app but I want the

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.