Private vs. Protected

This is a discussion on Private vs. Protected within the C++ Programming forums, part of the General Programming Boards category; My question is, what is the difference between these two keywords (if any) as they relate to classes?...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    41

    Private vs. Protected

    My question is, what is the difference between these two keywords (if any) as they relate to classes?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    protected: objects can be accesses only by methods of this and derived classes.
    private: objects can only be accessed by method of this class.

    use google and you will find lots of other explainations and examples, which all amount to the above.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    Quote from C++ from the Ground Up by Herbert Schildt
    When a base class is inherited by use of public, its public members become public members of the derived class, and its protected members become protected members of the derived class.
    When a base class is inherited by use of protected, its public and protected members become protected members of the derived class.
    When a base clas is inherited by use of private, its public and protected members become private members of the derived class.
    In all cases, private members of a base class remain private to that base class, and are not inherited.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Within a class protected is the same as private. However, protected members can be inherited in derived classes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# and SQL
    By siten0308 in forum C# Programming
    Replies: 2
    Last Post: 07-09-2008, 01:34 PM
  2. benefits of private or protected constructor
    By George2 in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2007, 02:02 AM
  3. webBrowser problem
    By algi in forum C# Programming
    Replies: 7
    Last Post: 08-19-2005, 10:35 AM
  4. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 12:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21