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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:38:14+00:00 2026-06-08T12:38:14+00:00

This is a question of pure curiosity, I don’t think the answer could cause

  • 0

This is a question of pure curiosity, I don’t think the answer could cause great improvements.

Let suppose there is this tree of inheritance:

           A
          / \
         /   \
       AB     AC
      /\       /\
  ABB  ABC   ACB ACC 

I have to write a function that executes differents actions basing on the object type.
I’m 100% sure that this object can only be an AC object or one of its childs.

now which code is faster:

 int t = getObjectType();
 A*  obj = getObject();
 switch (t) {
      case 0:
         ACB* casted_obj = static_cast<ACB*>(obj);
      case 1:
         ACC* casted_obj = static_cast<ACC*>(obj);
 }

or

 int t = getObjectType();
 A*  sup = getObject();
 AC* obj = static_cast<AC*>(sup);
 switch (t) {
      case 0:
         ACB* casted_obj = static_cast<ACB*>(obj);
      case 1:
         ACC* casted_obj = static_cast<ACC*>(obj);
 }

Probably C++ standards doesn’t say anything about how the tree of inheritance must be managed, so the answer depends on the implementation.

  • 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-08T12:38:15+00:00Added an answer on June 8, 2026 at 12:38 pm

    Static casts are done entirely at compile time, so the performance impact will always be zero. The only type cast done at run time is dynamic_cast. More: http://www.cplusplus.com/doc/tutorial/typecasting/

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

Sidebar

Related Questions

This question is for pure curiosity. Lets say I have lighttpd installed on my
This question is pure curiosity. In Xcode, why does this work: if (view.class ==
This is a question that arose mostly of pure curiosity (and killing some time).
NOTE: Perhaps this question could be answered by a pure Objective-C expert as well?
This question is out of pure curiosity. How does Cocoa define the id type?
This question exist only because of pure curiosity. Not a homework. Find the fastest
This is not a pure programming question, however it impacts the performance of programs
This question was here for other languages, so let here be one for Ruby.
This question is similar to what I need to do, but the voted answer
Hi I know this question have been asked before but the answers there isn't

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.