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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:54:03+00:00 2026-05-23T09:54:03+00:00

Let us say that I have a class A which is extended by B

  • 0

Let us say that I have a class A which is extended by B and C. Now, for want of polymorphism, I use base class pointer to point to the derived class object.

A *a = new B(); OR A *a= new C();

Now, let us say that I have executed few statements. now, I am interested in identifying the type of the object that the base class pointer is pointing to. How can this be done?

  • 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-23T09:54:03+00:00Added an answer on May 23, 2026 at 9:54 am

    The direct way would be to use dynamic_cast:

    B* b = dynamic_cast<B*>( a );
    if( b != 0 ) {
      // the object can be cast to class B safely
    }
    

    however the real answer is you don’t need to when you do polymorphism right – you have to use virtual functions and implement them appropriately in derived classes so that you can blindly call them and have the right code executed.

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

Sidebar

Related Questions

Let's say I have a class that has a member called data which is
Let us say that I want to create a class MyString which is a
Let's say you have a Generic Class which have a List<T> Items; Now think
Let's say that I have class , that uses some functionality of dict .
Let's say that I have a class Foo: public class Foo { public static
Let's say that I have a bunch of class instances that serve different purposes,
Let's say I have one class Foo that has a bunch of logic in
Let's say I have a class that implements the IDisposable interface. Something like this:
Let's say I have a class called Store that has many Employees. My RESTful
Let's say we have defined a CSS class that is being applied to various

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.