Sign in to follow this  
ender_341

what is the difference between protected and private(c++)?

Recommended Posts

Private means the data declared private within the class can only be altered by specially written "accessor" functions.

Protected means that the data is basically private, but it can be used by derived classes, whereas private data cannot.

HTH,

ukdeveloper.

Share this post


Link to post
Share on other sites
A little side not to add to ukdevelopers comment, protected only works its way down so say you have parent class Animal, and child class Dog and a child class Cat. Only public data can be read by parent clas Animal..not protected or private, even though the class Animal is a parent of Dog and Cat.

Share this post


Link to post
Share on other sites
Quote:
Original post by ricekrispyw
Quote:
Original post by frob
Your friends can touch your privates.

That's just a little disturbing...

It's also one of the most commonly used descriptions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this