Thread: problem in inheritance?

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    33

    problem in inheritance?

    hello,

    My question is that if I inherit a base class as protected in derived class,than am I allowed to use both getter and setter functions using protected members of base class in derived class?Or I can just set the value in derived class but can not return it in the scope of derived class.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    If the base class provides getter or setter functions, the derived class can call them - as long as those setters and getters are not private to the base class.

    Any member function of the derived class can also access (retrieve or modify the values) data members of the base class - again, as long as those data members are not private.

    Protected inheritence does not change that, except that functions which use the derived class cannot access the base class or any of its data or member functions (unless that function is a friend or member of the derived class).

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I've never heard of an actual use case for protected inheritance. It's in the language for the sake of consistency with member access control, but I really don't think anyone uses it in production.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Basically, protected inheritance turns all public members of the base class into protected members in the derived class. Protected and private members aren't touched.
    I take it that it's a good thing if you want to inherit from a base class which is set up for further derivation and make your your derived class also can be derived properly from.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    33
    thanx Elysia its clear now...cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance problem
    By logicwonder in forum C++ Programming
    Replies: 5
    Last Post: 10-07-2006, 10:14 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Multiple inheritance problem
    By Magos in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2006, 09:27 AM
  4. Inheritance using Stack Class Problem
    By dld333 in forum C++ Programming
    Replies: 17
    Last Post: 12-06-2005, 11:14 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM