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

ender_341 Author 136 June 03, 2005 02:10 PM what is the difference between protected and private? [edit] Thanks for the help Cancel Save -Matt S.

ukdeveloper 264 June 03, 2005 02:13 PM 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. Cancel Save

_jinx_ 139 June 03, 2005 02:19 PM 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. Cancel Save

frob 45,882 June 04, 2005 12:35 PM To make it simple:



Your friends can touch your privates. Your children cannot.



Children and friends know your protected stuff, strangers to not. Cancel Save

ricekrispyw 388 June 04, 2005 12:55 PM Quote: Original post by frob

Your friends can touch your privates.



That's just a little disturbing... That's just a little disturbing... Cancel Save The best way to predict the future is to invent it.