+ 1
What is the use of public and private in c++
2 Respostas
+ 1
To make members of a class or struct be accessible by other parts of the program outside the class/struct or not
+ 1
It also communicates the purpose of various functions in the code. Other objects interact using public methods, but internally in a class you can use private methods to do something too. It would be very confusing and messy if other classes could call private methods, because they usually require some context about the state of the object being processed, if that makes sense.
Basically it's to define the rules around how different parts of your program should interact