Results 1 to 4 of 4

Thread: Protected stuff

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    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.

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width