If i declare some variable in a class to be protected, the only way i can view or change it is if I write functions to do so. Well, what do "protected" and "private" mean actually, and what is the difference?
Printable View
If i declare some variable in a class to be protected, the only way i can view or change it is if I write functions to do so. Well, what do "protected" and "private" mean actually, and what is the difference?
When a var is declared as private it means that those members are accessible only from member functions and friends of the class. Protrcted means that those members are accessible only from member functions and friends of the class and its derived classes. When preceding the name of a base class, the protected keyword specifies that the public and protected members of the base class are protected members of the derived class.
Ok, i sort of get it. But, what is the whole purpose of it? I have heard "security" but i have no idea what it means.
No. Security has nothing to do with it. It's about reliability :) Private and protected members are to prevent users of your class from relying on things that may be implementation-specific, which is the point of OOP -- separate interface from implementation.