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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:13:46+00:00 2026-05-26T04:13:46+00:00

I am instantiating various objects based on an xml file. To create an object

  • 0

I am instantiating various objects based on an xml file. To create an object from a template I specify the datatype in the xml file. As I have quite a lot of templates and datatypes that should be supported I’d like to condense my code a little bit. I thought I could do this by using macros, but since I never really used to them, I have no idea how to do this. By providing a list of datatypes I’d like to support I thought I could simply write

  MACRO(A, dataTypes)

instead of:

if(s == "float")
{
    return new A<float>(name); 
}
else if(s == "int")
{
    return new A<int>(name); 
}
else if(s == "bool")
{
    return new A<bool>(name); 
}
else if(s == "std::string")
{
    return new A<std::string>(name); 
}
... 

But how can I define a macro like that?
The code should compile on Android as well, so it should not rely on another library like boost.

  • 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-26T04:13:46+00:00Added an answer on May 26, 2026 at 4:13 am

    The macro would be something like:

    #define MACRO(T) if (s == #T) { return new A<T>(blockName); }
    

    You only need a parameter (the type), because as far as I can see, A is fixed in your code.

    If you want to create the code for several types at once, this is not that easy. You should use something like boost preprocessor.

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

Sidebar

Related Questions

I have a specific question about instantiating a QuickTime object in Internet Explorer. QuickTime
I have an application that reads an input file with various user settings in
I found myself instantiating the same objects in numerous tests, so I'm trying to
I have this problem: After instantiating this Window, open all nested expanders on the
I am working with Active Directory using C#. Instantiating the PrincipalContext object seems to
I have a PHP class that, upon instantiation, creates a file that is unique
-- background -- I have a customer intranet (ASP.NET / VB) thats instantiating an
I have been reading a lot of articles explaining how to set up Entity
I have a PHP image upload system which allows a user to upload various
I have create a getDBConnection method in my Java application. This returns a connection

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.