0

I wanted to get a clearer idea of the differences between public, private and protected members in c++.

-Anything that is public is available to all derived classes of a base class, and the public variables and data for each object of both the base and derived class is accessible by code outside the class.

-Not only are the functions and variables marked private not accessible by code outside the specific object in which that data appears, but private variables and functions are not inherited

-Variables and functions marked protected are inherited by derived classes; however, these derived classes hide the data from code outside of any instance of the object

I guess I'm not really clear on the differences between private and protected. Are private members accessible only to the method of the class?

Is there access to private members of a class by any function defined outside the class?

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
Richard
  • 1
  • 2
  • Here is an excellent link that explains all the nuances and subtleties of those accessors: http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance – isaac.hazan Feb 22 '15 at 18:24
  • I'd add that `private` components of a class are indeed also part of derived classes. They just can't be accessed (except if there is a `protected` or `public` accessor function). – Mats Petersson Feb 22 '15 at 18:31

0 Answers0