+ 1

What is the use of public and private in c++

27th Jul 2019, 3:11 PM
Vaibhav Mishra
2 Antworten
+ 1
To make members of a class or struct be accessible by other parts of the program outside the class/struct or not
27th Jul 2019, 3:18 PM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 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
27th Jul 2019, 10:52 PM
Dan Walker
Dan Walker - avatar