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

  • Home
  • SEARCH
  • 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 916577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:04:29+00:00 2026-05-15T18:04:29+00:00

I am stuck with a design problem that I hope you guys can help

  • 0

I am stuck with a design problem that I hope you guys can help with. I have a few different classes that have various parameters (more than 20 in each case, and they are mostly different, although some are exactly the same in which case they inherit from a base class). I want to control these parameters through the user of a class called ObjectProperties. Each class will create ObjectProperties and populate it with it’s own parameter list when the class is initialized. This is done with a map which is set up like so:

std::map<std::string, [data_type]> // where [data_type] can be an int, float, bool, string etc.

the ‘string’ is the name for the parameter and the data type is the type it’s associated with. This is done for easy scripting later on (instead of having 20+ getters/setters). I have already made the ObjectProperties class, but it is less than ideal. I have a structure with all the possible data types called DataTypeStruct and a variable for the map in the ObjectProperties class called pDataTypeMap;

typedef struct
{
   int* IntValue;
   float* FloatValue;
   bool* BoolValue;
   std::string* StringValue;
}DataTypeStruct;

std::map<std::string, DataTypeStruct> pDataTypeMap;

When a class wants to add a parameter for manipulation, it calls one of the following functions, which then creates a new structure appropriately and pairs it with the name to be put in the map. The function returns true or false depending on whether it was able to insert it or not (if false, then the name already exists)

bool AddParam(std::string aName, int* aParam);
bool AddParam(std::string aName, float* aParam);
bool AddParam(std::string aName, bool* aParam);
bool AddParam(std::string aName, std::string* aString);

The reason aParam is/are pointers is because it is required that the parameters must be passed by reference so that they can be manipulated later on.

To change the value for the parameter I have similar functions. As you can see, this is less than ideal, as I have wasted some space with the structure (where each new structure only stores an int OR a bool OR a string OR a float), and calling overloaded functions is unsafe (I ‘can’ make the functions have unique names, but again, that is less than ideal).

I hope I have explained the design issue that I have come across (it is a little difficult to explain) and would really like to hear suggestions on how to go about solving this problem.

  • 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-15T18:04:29+00:00Added an answer on May 15, 2026 at 6:04 pm

    I would suggest first taking a look at boost::any, boost:variant, boost::tuple or boost::fusion::vector as the ‘vehicles’ for your [data_type].

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

Sidebar

Related Questions

No related questions found

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.