member access and inheritance

This is a discussion on member access and inheritance within the C++ Programming forums, part of the General Programming Boards category; Suppose I have a class with a protected virtual function class Super { protected: virtual void Func() {} }; You ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    201

    member access and inheritance

    Suppose I have a class with a protected virtual function

    class Super
    {
    protected:
    virtual void Func() {}
    };

    You inherit publicly from this class and override Func, but now in the public section.

    class Sub : public Super
    {
    public:
    virtual void Func() {}
    };

    Has the access modifier changed then or can't you change those?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Changed based on the class object.

    Kuphryn

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Inheritance 101:




    Super class to public Derived class

    public = stays public
    protetcted = becomes public
    private = private



    Super class to protected Derived class

    public = protected
    protected = protected
    private = private





    Super class to private Derived class

    public = private
    protected = private
    private = private
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    I think your Inheritance 101 isn't quite right:
    Inheritance 101:

    Super class to public Derived class

    public = stays public
    protected = stays protected
    private = completely inaccessible (private to Super class).


    Super class to protected Derived class

    public = protected
    protected = protected
    private = completely inaccessible (private to Super class).


    Super class to private Derived class

    public = private
    protected = private
    private = completely inaccessible (private to Super class).
    Of course, that all becomes irrelevant in the OP's case, since the protected virtual function was overridden as a public function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with pointers to an abstract class and inheritance
    By bainevii in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2009, 08:51 AM
  2. public/private inheritance
    By xion in forum C++ Programming
    Replies: 3
    Last Post: 06-17-2004, 07:36 PM
  3. Back with some inheritance fun
    By hpy_gilmore8 in forum C++ Programming
    Replies: 11
    Last Post: 01-17-2004, 12:15 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. inheritance & virtual functions
    By xagiber in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2002, 12:10 PM

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