Thread: Public Inheritance Clarification

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    Public Inheritance Clarification

    Is containment or compositon, public inheritance?

    Private members become accesible only through the base class interface.

    Does this mean private members of the contained class are only accesible through the public methods of that class?

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    i can't help you out much, but i'm pretty sure composition is not public inheritance. as far as i know, it's only declaring an object of class A within class B, and then passing the arguments to the newly created object.

    >Private members become accesible only through the base class interface.

    i think that's refering to the fact that two derived classes of the same base class do not have proteced acces to each other.

    that's all i know right now. hope i helped a little?

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537

    Re: Public Inheritance Clarification

    Originally posted by rip1968
    Does this mean private members of the contained class are only accesible through the public methods of that class?
    This is true for public inheritance.

    class A
    {
    public:
    int getNum( );

    private:
    int num;
    };

    class B
    {
    public:
    int getNum( );
    };

    int B::getNum( )
    {
    return A::getNum( ); //cannot directly access A::num
    }

    //sorry for the lag of tags, this was written on the fly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Process Memory
    By polydegmon in forum C# Programming
    Replies: 0
    Last Post: 05-26-2009, 07:18 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Linking problems in Visual Studio
    By h3ro in forum C++ Programming
    Replies: 5
    Last Post: 03-04-2008, 02:39 PM
  4. Stuck with Structs...
    By DanFraser in forum C# Programming
    Replies: 8
    Last Post: 05-03-2007, 09:55 AM
  5. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM