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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:12:46+00:00 2026-06-06T07:12:46+00:00

I’m working on a small framework in C++ to use in some of my

  • 0

I’m working on a small framework in C++ to use in some of my projects, to statically link against as a utility library of sorts. I guess you could compare it to a more domain-specific to my personal needs, and simpler library like juce. This is as much a learning and experience exercise as anything else, so I’d like to take the time to do things properly and understand the techniques I apply. I’m currently working in linux, but aiming for the code to be portable, so this will allow me to write any platform specific code to an interface.

At the moment I’m working on a basic messaging system, which I would like to allow for messages that include objects of various types. My initial thought was like so:

class Message {
  virtual std::string type;
};
class DataMessage : Message {
  std::vector<std::string> *data;
};

My question is, what is the best way to identify that a Message is a DataMessage, and either cast it to its actual type, or access the data it contains?

I can use a string for the type like above, but that doesn’t guarantee each subclass will actually have a unique type id. Also, I wonder if the overhead of string processing would be slower than an alternative (could I extend an enum, for example?).

As for accessing the data, if I can cast the Message to its proper type, this is not an issue. Otherwise, I could add a virtual function to the base class as either an accessor (but then how do I have it use a different return type to the one specified in the base class? What if the class doesn’t need any additional data?), or as a worker function that acts on the data (but I would rather have it just as a data passing mechanism between classes, versus a callback style framework).

Any suggestions, alternatives or links are much appreciated. Discussion of different approaches would be awesome!

Thanks in advance guys.

  • 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-06T07:12:47+00:00Added an answer on June 6, 2026 at 7:12 am

    You can use DataMessage* pDataMessage = dynamic_cast<DataMessage*>(pMessage). The pDataMessage will be valid only if pMessage is a DataMessage object. Otherwise it will be NULL.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.