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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:57:41+00:00 2026-06-10T01:57:41+00:00

I am currently working on a Component based game engine written in c++. All

  • 0

I am currently working on a Component based game engine written in c++. All components inherit from a component base class. All components in the scene are upcasted into a vector of Components were they can be iterated over and Update() and such can be called.

I am trying to come up with a communication system for the components. If I have a function called GetComponent<Type>() Like Unity will I be able to return a component from what is used to be before it was upcasted.

So basically i have an upcasted component and I want to reverse it so it is its original class and then return it via the function(as the class it used to be). Is this possible? If it were possible how would the component know what class it used to be?

Are there any examples of doing this I can learn from?

  • 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-10T01:57:43+00:00Added an answer on June 10, 2026 at 1:57 am

    For this to work you would have to know the original type of the component as it was before adding it to the collection (upcasting it).

    So knowing that, it can be done like this (assuming component is of type Component*):

    SpecificComponent* specific = dynamic_cast<SpecificComponent*>(component);
    

    Not that dynamic_cast can fail => the above can set specific to nullptr if the actual component type is not applicable. That, and the fact that it is slower than the other casts make it the most disliked of the C++ casts.

    You can also take a look at boost::polymorphic_downcast, which is similar in function. It makes a dynamic_cast and asserts if it fails in DEBUG mode, but does the faster static_cast in RELEASE mode.

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

Sidebar

Related Questions

I am started working on resume retrieval(document) component based on lucene.net engine. It works
Currently working in the deployment of an OFBiz based ERP, we've come to the
Im currently working on a game that uses multi touch to apply zoom to
Alright, so I'm currently working on a game and ran into a memory issue
I'm currently working on a GUI based application and am using the code-generation feature
Currently, we are working on a C++ legacy code base, which consists of several
I'm currently working on a small console application. This application is based on a
I'm currently working on an application where one component of the application needs to
currently I am working on a spring based application. I do have some unit
Currently i working on an Android based mobile application. It will be integrated to

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.