Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by ender_341 Jun 3, 2005 at 2:10 PM 4 replies 30.5k views
Original Post
ender_341
ender_341
what is the difference between protected and private? [edit] Thanks for the help
-Matt S.
ukdeveloper
ukdeveloper
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.
_jinx_
_jinx_
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.
frob
frob
To make it simple:

Your friends can touch your privates. Your children cannot.

Children and friends know your protected stuff, strangers to not.
ricekrispyw
ricekrispyw
Quote:
Original post by frob
Your friends can touch your privates.


That's just a little disturbing...
The best way to predict the future is to invent it.
frob
frob
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.