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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:48:17+00:00 2026-05-27T14:48:17+00:00

I have a class containing a set of attributes, which I want to be

  • 0

I have a class containing a set of attributes, which I want to be able to have default values get from another instance (named parent).

If the instance does not have a parent, then it is assigned default values.
But if the instance have a parent, then I would like it to default its attributes to the parent’s ones, with the restriction that if the parent attributes are modified then the object attributes can also get the new value.
Given this restriction, I can’t simply copy the values from the parent.

Thus I think I have two methods:

  • Use pointers: if the pointer is nullptr then use the parent value.
  • Use a bool field for each attribute, indicating the status.

Both methods should work, but they also have incovenient:

  • The first will need manual instantiation even if it can be simplified with shared_ptr or unique_ptr. But this will lead to additional instructions, thus slower code
  • The second will lead to additional memory consumption : each instance will take at least one more byte (most of time 2, 4 or even 8 bytes) per attribute.

My question is: Is there any other way to implement such behavior? Or what is the best solution?

  • 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-27T14:48:18+00:00Added an answer on May 27, 2026 at 2:48 pm

    The second will lead to additional memory consumption : each instance
    will take at least one more byte (most of time 2, 4 or even 8 bytes)
    per attribute.

    Then use a bitfield or bit mask to use one single bit for each attribute. Nothing more efficient than that.

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

Sidebar

Related Questions

I have a class containing a set of C dynamic arrays which are all
I have a class A containing two pointers to objects of another class B.
I have a class whose instances have attributes that are containers which themselves contain
I have class containing an std::set of boost::weak_ptr<T> . I have two functions begin()
I have an autogenerated class from importing a web service containing something like this
I have a class containing a collection of items. For convenience I've provided GetCurrentItem
I have a class containing Linq To SQL objects that are used to populate
I have a class containing several properties (all are strings if it makes any
I have a class library containing several structures each consisting of several value and
I have an example class containing two data points: public enum Sort { First,

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.