Jump to content
  • Advertisement
Sign in to follow this  
ender_341

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

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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
To make it simple:

Your friends can touch your privates. Your children cannot.

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!