help with inheritance!

This is a discussion on help with inheritance! within the C++ Programming forums, part of the General Programming Boards category; I am learning Object-Oriented Programming and I missed the class on inheritance. I am going through some problems in my ...

  1. #1
    Unregistered
    Guest

    Question help with inheritance!

    I am learning Object-Oriented Programming and I missed the class on inheritance. I am going through some problems in my textbook and I came across a few questions which I don't understand. There is a table given and you have to list all the private, protected, and public members on each Class. If someone could please help me to understand what gets passed to each. If someone could explain what gets passed to Class_B, I might be able to figure out the rest.

    TABLE
    ----------------------------------------------
    Base Class Member Access Category
    ----------------------------------------------
    private
    protected
    public
    ----------------------------------------------
    Derived Class Public Base Class
    ----------------------------------------------
    private
    protected
    public
    ----------------------------------------------
    Derived Class Private Base Class
    ----------------------------------------------
    private
    private
    private
    -----------------------------------------------

    class Class_A
    {
    private:
    int A_private;
    protected:
    int A_protected;
    public:
    Class_A(int, int);
    void A_Pub_Func();
    };

    class Class_B : public Class_A
    {
    private:
    int B_private;
    protected:
    int B_protected;
    public:
    Class_B(int, int);
    void B_Pub_Func();
    };

    class Class_C : private Class_A
    {
    private:
    int C_private;
    protected:
    int C_protected;
    public:
    Class_C(int, int);
    void C_Pub_Func();
    };

    class Class_D : public Class_B
    {
    private:
    int D_private;
    protected:
    int D_protected;
    public:
    Class_D(int, int);
    void D_Pub_Func();
    };

    class Class_E : public Class_C
    {
    private:
    int E_private;
    protected:
    int E_protected;
    public:
    Class_E(int, int);
    void E_Pub_Func();
    };

  2. #2
    Unregistered
    Guest
    class derived-class-name: access base-class-name{
    // body
    };

    Access of base class members inside of derived class is determined by access (above). Access may be public, private, or protected ( private is default ).

    When access is public,
    -public members become public,
    -protected members become protected,
    -private members are not accessible in derived class.

    When access is private:
    -All public and protected members become private
    -private members are not accessible in derived class

    When access is protected:
    -All public and protected members become protected
    -private members are not accessible in derived class

    So:
    B_class inherits:
    A_protected (as protected member)
    Class_A(int, int) (public)
    void A_Pub_Func() (public)

    Hope this helps.

  3. #3
    Unregistered
    Guest

    Talking

    Thanks a bunch!!!

    It helps a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Virtual inheritance
    By 6tr6tr in forum C++ Programming
    Replies: 13
    Last Post: 05-07-2008, 11:20 AM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 08:04 AM
  4. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 03:41 AM

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