private inheritance

This is a discussion on private inheritance within the C++ Programming forums, part of the General Programming Boards category; Hello I am having difficulty in getting my head around private inheritance. Can anyone give a simple explanation of what ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    Question private inheritance

    Hello

    I am having difficulty in getting my head around private inheritance. Can anyone give a simple explanation of what it is and a simple example of when you might need to use it?

    Its something to do with the level of access and what that access has been granted to that I don't get...

    Help!

    Da_fall_guy

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    When you inherit as "public", everything that was "public" in the base class is "public" in the derived class.

    i.e. A public function in the base class can be called from a user program which has declared an instance of the derived class.

    When you inherit "private", everything that was "public" in the base class becomes "private" in the derived class.

    i.e. A public function in the base class cannot be called from a user program which has declared an instance of the derived class. Internally, the derived class can call the "public" members of the base class.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Thankyou adrianxw

    That has cleared that up for me.

    So with private inheritance the derived class can access all data/methods in the base class via methods of its own. Is that right?

    Instances of the derived class can then access the methods/data in this mediated way?

    Do you know of any examples a beginner might understand?

    Thanks again

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>>
    So with private inheritance the derived class can access all data/methods in the base class via methods of its own. Is that right?
    <<<

    Internally, the class can directly access any public members of the base class. Remember that at all times, private members of the base class are not accessible to the derived regardless of the inheritence qualifier.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

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, 12:34 PM
  2. webBrowser problem
    By algi in forum C# Programming
    Replies: 7
    Last Post: 08-19-2005, 09:35 AM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  4. help with inheritance!
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 08:08 AM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 11:07 AM

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