+ 1

What does private and public mean?

7th Dec 2016, 10:14 PM
Paweł Chrząstowski
Paweł Chrząstowski - avatar
2 Respuestas
+ 2
In defining for classes the general syntax is class Class name { private: //private functions and variables public: //public functions and variables } Example: class Rectangle { private: int width, height; public: void set_values(int x, int y){width = x; height = y;} I made a class called Rectangle. I want that no one can access what the variable width or height are except the public class members so I made them private, but i want that any user of mine can also set the value of the rectangle to his own privacy so i created a method (a PUBLIC method) so he can do this. } As an analogy you can think of it as thinks you want to keep private and things you want shared or made public
7th Dec 2016, 10:28 PM
JENN
JENN - avatar
+ 1
thanks a lot
7th Dec 2016, 10:36 PM
Paweł Chrząstowski
Paweł Chrząstowski - avatar