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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:48:27+00:00 2026-06-13T18:48:27+00:00

Here is my MESSAGE structure: struct tEventMessage { // Type of the event int

  • 0

Here is my MESSAGE structure:

struct tEventMessage 
{
    // Type of the event
    int Type;

    // (void*) Allows those to be casted into per-Type objects
    void *pArgument1;   
    void *pArgument2;

};

Can i add some kind of ‘template’ member to this structure, so that later on when building message i can pass those pointers + and any other data i wish ? ( see example below )

struct tEventMessage 
{
    // Type of the event
    int Type;

    // (void*) Allows those to be casted into per-Type objects
    void *pArgument1;   
    void *pArgument2;

    // Template
    T tSomeTemplateMember;
};

 void HandleClick(....)
 {
 CVector3 vNewPosition = ....

 tEventMessage _msg;
 _msg.Type = xxxx;
 _msg.pArgument1 = pA->GetObjectPointer();

 //
 // Wrong!
 // Because this CVector3 will not be alive in next tick
 // - my pointer will point to nothing.
 //
 _msg.pArgument2 = static_cast<CVector3*>(&vNewPosition)


 //
 // Something like that would be great
 // And would allow me to use CVector2,CVector3,CVector4 with one template member
 // 
 _msg.tSomeTemplateMember = vNewPosition;

 }
  • 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-13T18:48:28+00:00Added an answer on June 13, 2026 at 6:48 pm

    I think you’re over complicating the problem. Instead of one problem, how to pass arbitrary data in a message, you now have two, how to cope with templates as well.

    The usual method to implement this sort of thing is to use inheritance:-

    class Message
    {
    public:
      int Type () { return type; }
    protected:
      int type;
    };
    
    class ClickMessage : public Message
    {
    public:
      ClickMessage () { type = ClickMessageID; }
    private:
      // the message data
    };
    
    void HandleMessage (Message *message)
    {
      switch (message->Type ())
      {
      case ClickMessageID:
        HandleClick (reinterpret_cast <ClickMessage *> (message));
        break;
      default:
        // unhandled message error
        break;
      }
    }
    
    void HandleClick (ClickMessage *message)
    {
      // do stuff
    }
    

    The problem is you end up repeating a lot of code, i.e the cast in the switch statement. There’s also a maintenance issue too – added new messages requires a bit of careful updating. You could hack the code a bit and use function pointers and a map to convert message types to functions and replace the switch statement.

    There might be a clever template solution, but I can’t think what it might be.

    Using RTTI might help (at a cost).

    This is one problem that reflection is really good at solving!

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

Sidebar

Related Questions

Here is my code: void subroutine(const char *message) { printf(message); } And here is
struct Message { char type; double idNum; char *Time; char *asset; bool BS; float
I have an application that deals with data in the following structure: struct Message
I have a structure: typedef struct { LogLevel level; char message[255]; } LogMessage; I
Here is the message. What's wrong with it? Is it a installtion problem? TITLE:
Here is the complete error message that I get in the Package Manager Console
Here I have to send and receive dynamic data using a SysV message queue.
here's the main code at first I thought is was the message box but
Here is what I am trying to do: The server sends message to connected
here is my question, this is my string: var body = { message: Hello,

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.