why use "private:"? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

why use "private:"?

I cant find any use for making class members private, it seems like a meaningless thing to do. Or there is a reason? Please tell me what it is

31st Aug 2017, 7:26 PM
Data
Data - avatar
1 Antwort
+ 6
* Reduces error risk of code * Makes things easier to read (When something is private you know for a fact it is only something within the class) So it's essentially for maintainability and understandability. Really good analogy by the top comment here: https://stackoverflow.com/questions/24661886/reason-for-making-class-members-private As the guy from that link said, I always make things private (Only private) until I need to make it public or protected.
31st Aug 2017, 7:40 PM
Rrestoring faith
Rrestoring faith - avatar