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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:22:33+00:00 2026-06-01T11:22:33+00:00

I have this problem again and again… and still have not a satisfactory answer…

  • 0

I have this problem again and again… and still have not a satisfactory answer…

Especially when I put the class into a container, later on I need to record more information on every element in the container during a specific processing, but after processing I do not need the extra information anymore….

I often found some libraries try to solve the above situation by defining a void* in their data structure to provide user-defined data structure extension. Just the same described in this Q&A.
But it produces memory / resource handling problem… and other problems that I feel this approach is error-prone.

In the modern day of object-oriented programming, I am thinking of
using inheritance & polymorphism. Use base class’s pointer in the container, but then I have to add derived class’s accessor into the base class. It is kind of strange…

is there any other better ways to extend a class’s property while maintain container comparability in C++?

  • 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-01T11:22:35+00:00Added an answer on June 1, 2026 at 11:22 am

    The best way to store extra data about a object without actually compromising the integrity of the object itself is to store a pair of data in the container instead.

    struct User { ... };
    struct ExtraData { ... };
    typedef std::pair<User, ExtraData> UserAndExtraData;
    

    Now I can create a container type in C++ which stores both pieces of information together without compromising the independence of either type.

    std::vector<UserAndExtraData> vector;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into this problem again and now really need to know how
I have this problem I'm hoping someone knows the answer to. I have an
i have this problem: ms-access could not delete and i found a potential solution
I have this problem decomposing a relation schema into a set of schemas that
I run into this problem again and again; Situation there is a (large) dataset
It is hard to put this problem into words, but a real world example
Greetings again, I have this problem again on C but now using struct. Having
I have this stranger problem on Nivo slider that the images are not centrally
I have looked into this time and again and have read solutions but they
I have this problem where I open Visual Studio and the internal windows are

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.