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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:36:38+00:00 2026-05-11T09:36:38+00:00

When do you use each inheritance? class Base{}; class Derived: protected Base{}; class Derived2:

  • 0

When do you use each inheritance?

class Base{};  class Derived: protected Base{}; class Derived2: public Base{}; 

My case:

I have class called Snapshot which only contains GetXXX methods. It is a light-weight classed used to store current state of the Value class. I also use it for recovery, keeping instances of this class long after Value class instance are gone. A Manager class, processes instances of the Snapshot class. Let me show you the code:

class Snapshot {         public:             Snapshot (const Snapshot * snap)             {               _x=snap->_x;                  _y=snap->_y;                 _z=snap->_z;               }             Snapshot (){_x=_y=_z=0;}             int GetX(){return _x;}             int GetY(){return _y;}             int GetZ(){return _z;}             ~virtual Snapshot(){}            protected:               int _x,_y,_z;                };  class Value:public Snapshot  {   /*Very heavy class with a lot of components used to calculate _x, _y, _z*/   };   class Manager {        public:          void Process( const Snapshot * snap)          {           }   }; 

How do you feel about this design? What are the alternatives?

Thanks

Solutions and issues

  • Solution: I would create makeSnapshot function which would return Snapshot object by given Value object.

  • Issues:

    • major issue: I sent snapshots at very frequently (every second, even less), hence I don’t want to incur the construction and destruction cost minor issue:

    • semi-major issue I will have to make Value a friend of Snapshot, as I don’t want
      to introduce setters.

  • 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. 2026-05-11T09:36:38+00:00Added an answer on May 11, 2026 at 9:36 am

    Generally speaking I would use public inheritance, if I want to implement a specific interface, e.g. if my class is to be accessed thrugh a specific contract. Protected inheritance could be used, if you just want to reuse the functionality implemented in the parent.

    I would make Snapshot a pure virtual class, e.g. just an interface, and Value would implement the getXYZ methods. E.g. you probably don’t need the _x,_y,_z members in Snapshot.

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

Sidebar

Ask A Question

Stats

  • Questions 139k
  • Answers 139k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd look into perlipc(1) for SystemV semaphores or modules like… May 12, 2026 at 7:39 am
  • Editorial Team
    Editorial Team added an answer That message isn't a mail error. PHP cannot open the… May 12, 2026 at 7:39 am
  • Editorial Team
    Editorial Team added an answer Depending on the OS of the target system, you may… May 12, 2026 at 7:39 am

Related Questions

I have a design problem which I would like some input on. Here are
The open-closed principle states that Software entities (classes, modules, functions, etc.) should be open
What is the difference between the following set of pointers? When do you use
At the startup I'm working at we are now considering scaling solutions for our

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.