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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:14:05+00:00 2026-05-29T19:14:05+00:00

I have an application which will be receiving messages from another application. These messages

  • 0

I have an application which will be receiving messages from another application. These messages will be XML fomatted strings, and they will contain a <messageType> tag. The message type will identify this message as a type of internal message. The following code shows my internal message structures.

namespace
Application1{

enum ApplicationAttributes{
    ApplicationName = 1000,
    Start,
    Stop,
    Pause,
    Save,
    Discard,
    SelectRunway,
    DoAlignment,
    RedoAlignment,
    AlignmentOK,
    DoCalibrationStage1,
    SetCalibrationStage1,
    SetCalibrationStage2,
    SetCalibrationStage3,
    CancelCalibration,
    CalibrationOK
};


struct Alignment{
    int x;
    int y;
    int error;
};

struct Calibration{
    int x;
    int y;
    int error;
};

}

alignment and calibration are the two internal message structures.

What I’m trying to do is build a ‘message interpreter’ which will receive an XML string, decode it and return any one of the structs shown above; so if the <messageType> is ‘alignment’, the message interpreter will build an alignment struct, and return that.

So ultimately, I’m trying to make a template function, which can return an arbitrary struct, based on what i read in from <messageType>.

Are my objectives clear? is my approach the right one?

Let me know if I should clarify, or if I should take a different approach.

  • 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-29T19:14:07+00:00Added an answer on May 29, 2026 at 7:14 pm

    I don’t believe a template function makes sense. Your input is always going to be a string, and C++ can’t differentiate function signatures based on return type alone – so I don’t know how a template would help – what would the type argument be?

    I’d suggest making your function a normal one that parses out the messageType and allocates a struct based on it – you can use whatever constructs you want for this.

    The trick would be (in my mind) to derive all of your internal-message-classes from the same empty base class – you could then return a pointer to that base class back from your function, and it will hold whatever type got created.

    It be a good idea to return an enumeration along with the pointer in a std::pair which you can use to determine the correct derived type that was created, that way you can cast the result directly to the correct derived type with a static_cast.

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

Sidebar

Related Questions

I have an application which will use WCF to serve up various chunks of
I have a silverlight application which users will be running in various time zones
I'm designing an application which will have a network interface for feeding out large
I have an idea for a simple application which will monitor a group of
I want to create an application which will have a client and server components.
I'm looking at building a Rails application which will have some pretty large tables
I need to write a standalone Java application which will have a embedded HTTP
I'm thinking how to arrange a deployed python application which will have a Executable
I want my application to have a zoomable element which will allow the XAML
I have to develop an application with which my client will do visual design.

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.