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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:34:33+00:00 2026-05-23T01:34:33+00:00

In our application we have an object that receives attributes at runtime. For example,

  • 0

In our application we have an object that receives attributes at runtime. For example, to add a float to the object:

my_object->f("volume") = 1.0f;

Retrieving the volume works the same way:

cout << my_object->f("volume") << endl;

Internally, this is represented by a map of strings to their respective type. Each type has its own access methods and map. It looks like this:

map<string, float> my_floats;
map<string, int> my_ints;
map<string, void *> my_void_pointers;

Oh, the dreaded void *. Sometimes we need to add classes or functions to the object. Rather than have a separate map for every conceivable type, we settled on a void * map. The problem we’re having is with cleanup. Currently, we keep around a list of each type of these “dangling” objects that the void * point to, and call a cleanup function on these separate lists when necessary.

I don’t like having to use void * and all the extra attention it requires for proper cleanup. Is there some better way to store arbitrary types in an object at runtime, accessible via a string map, and still benefit from automatic cleanup via destructor?

  • 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-23T01:34:33+00:00Added an answer on May 23, 2026 at 1:34 am

    This post seems to be a good answer to your question.

    Storing a list of arbitrary objects in C++

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

Sidebar

Related Questions

We have an application that downloads some files in the background. Our application pops
In our application we sometimes have to make minor GUI modifications for different customers:
In our web application we have a directory which resides outside of the project.
Our application is interfacing with a lot of web services these days. We have
Our application is well structured (well we did our best!) and we have split
Have Log4Net configured in our application to use a date stamped name and a
We have in the process of upgrading our application to full Unicode comptibility as
We have a situation where our application calls some stored procedures on a sql
We have some issues in our application with skype taking over some of our
I have a web reference for our report server embedded in our application. The

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.