You are here:



When we inherit a base class with access modifier

Q-->Is its private data members is inherited?  

Hello vikas, thanks for the question.

To answer your question, I had to do a bit of refreshing myself. No, private members are not inherited. In fact, private members are never inherited, even with public inheritance. I always just made my base class variables protected so I wouldn't have to write all the accessors for them so the derived class could get at them. If you want to get at the base classes private variables in a derived class, write an accessor function in the base class so the derived class will inherit the accessor, and can do what it needs to do that way.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.