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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:19:44+00:00 2026-06-02T04:19:44+00:00

I am developing a big hierarchy of classes for a framework that will require

  • 0

I am developing a big hierarchy of classes for a framework that will require quite a lot of type casting when it gets done.

My question is, how stupid of an idea is to put in a static member that uses an enum to store all the object types in the hierarchy. Having the member static for every class will not increase the instanced object sizes, and will give a (potentially) faster way to determined the type of an object during runtime than dynamic_cast.

At least that’s the basic idea. How adequate would this approach be, and are there any potential flaws?

  • 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-02T04:19:47+00:00Added an answer on June 2, 2026 at 4:19 am

    I don’t know how you were gonna determine the type of each object from a static variable that is shared between the objects. Unless you have some virtual function that you override for each class, but then you don’t need the static variable at all, just do something like this:

    struct Base
    {
       virtual int type() = 0;
    };
    
    struct Derived1 : public Base
    {
       virtual int type() { return 1; }
    };
    
    struct Derived2 : public Base
    {
       virtual int type() { return 2; }
    };
    

    Not the fastest solution, but several magnitudes faster than dynamic_cast or typeid.

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

Sidebar

Related Questions

Im developing an app that shows big images.. There are a lot of images
We're developing quite a big application using ASP.NET MVC and at the beginning we
I am developing a web service and it is of big importance that I
I'm developing application for android. my application has very big size (APKfile) that is
Ok guys. I've begun developing a little sparetime project that might become big someday.
I'm currently developing an application that needs to parse some (a big file of)
I'm developing a web site and I notice that there is a big difference
I've a big problem with the iPhone application that I'm developing. When you run
I'm developing an application for companies that will automatically post data on their social
We're developing an accounting and ERP application (something that lots of companies, big and

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.