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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:50:47+00:00 2026-05-22T17:50:47+00:00

I recognize the questions title is a bit vague, so thanks for at least

  • 0

I recognize the questions title is a bit vague, so thanks for at least reading it 😉

My situation is this: I have got a set of classes CommandA, CommandB, … derived from a common pure abstract base class ICommand. Now I need to keep instances of those derived classes in some kind of container but with the restirction that only one of each derived type should be allowed inside the container at any time. Instead when an item of already present derived type is inserted into the collection replacing the existing instance with the new one would occur.

Furthermore there is the need to remove a item from the collection based on its type.

I assume this would require some sort of type-identification at runtime. I have ruled out Runtime-Type-Identification as provided by the C++ compiler because we might at some point required to compile the project on (yet unknown) older compilers. Most witty template tricks thus probably also out of the game. But frankly I still would highly appreciate to not assign some numerical identfier to my derived classes by hand…

I am grateful for every hint on the issue.

Thanks alot in advance,

Arne

  • 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-22T17:50:47+00:00Added an answer on May 22, 2026 at 5:50 pm

    If you cannot use template or RTTI you can do something like this

              class ICommand
        {
            virtual void *getStaticId() = 0;
        }
    
    
    
        int bar;
        void* CommandA::getStaticId()
        {
            return &bar;
        }
    
    
        int foo;
        void* CommandB::getStaticId()
        {
            return &foor;
        }
    

    You can use the address of static variable per class as their typeid

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

Sidebar

Related Questions

Actually I have trouble naming the title of this post. Because I don't know
This question is not language-aware. I wanna know how can I recognize a returning
Can anybody recognize the 2 fonts on this logo? http://www.networkdance.com/logo.jpg
I know there are other questions that are very similar to this, but their
I got yelled at for trying to use the word question in the title
TLDR: Started with this question simplified it after got some of it working and
I need to recognize the speech from a set of WAV files that are
My questions is simple: Does the compiler recognize a property determined in Interface Builder
i have little problem how i will recognize which item was clicked with OnClickEvent.
After spending half an hour to find a proper, self-explaining title for this question,

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.