|
-
Jun 8th, 2001, 11:48 PM
#1
Thread Starter
Fanatic Member
Protected stuff
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?
Alcohol & calculus don't mix.
Never drink & derive.
-
Jun 9th, 2001, 05:19 AM
#2
Frenzied Member
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.
-
Jun 9th, 2001, 05:12 PM
#3
Thread Starter
Fanatic Member
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.
Alcohol & calculus don't mix.
Never drink & derive.
-
Jun 9th, 2001, 06:06 PM
#4
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|