By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Changing access levels of inherited base members

P: n/a
Hello NG,

Regarding access-declarations and member using-declarations as used to
change the access level of an inherited base member...

Two things need to be considered when determining an inherited base member's
access level in the derived class: its access level in the base class and
the type of inheritance (public, protected, or private). After this
determination is made, the following possibilities exist for manually
changing the access level, in the derived class, of the inherited base
member as long as it is not inaccessible in the derived class:

1. It can be set no higher than what it was in the base
2. It can be set only to exactly what it was in the base
3. It can be set to anything

If it *is* inaccessible in the derived class, it must remain so.

I have seen statements in published books that 1 is the case. I have also
seen statements in published books that 2 is the case. Empirically, I have
observed that 3 is the case (as the results below indicate). Can somebody
please confirm that 3 is indeed what's permitted by the language?

Thanks,
Dave

Access level in base: inaccessible
Type of inheritance: public
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: private
Type of inheritance: public
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: protected
Type of inheritance: public
Resulting access level in derived: protected
Access level in derived can be raised to: public
Access level in derived can be lowered to: private

Access level in base: public
Type of inheritance: public
Resulting access level in derived: public
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: private, protected


Access level in base: inaccessible
Type of inheritance: protected
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: private
Type of inheritance: protected
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: protected
Type of inheritance: protected
Resulting access level in derived: protected
Access level in derived can be raised to: public
Access level in derived can be lowered to: private

Access level in base: public
Type of inheritance: protected
Resulting access level in derived: protected
Access level in derived can be raised to: public
Access level in derived can be lowered to: private


Access level in base: inaccessible
Type of inheritance: private
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: private
Type of inheritance: private
Resulting access level in derived: inaccessible
Access level in derived can be raised to: <None>
Access level in derived can be lowered to: <None>

Access level in base: protected
Type of inheritance: private
Resulting access level in derived: private
Access level in derived can be raised to: public, protected
Access level in derived can be lowered to: <None>

Access level in base: public
Type of inheritance: private
Resulting access level in derived: private
Access level in derived can be raised to: public, protected
Access level in derived can be lowered to: <None>
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
* Dave:

Two things need to be considered when determining an inherited base member's
access level in the derived class: its access level in the base class and
the type of inheritance (public, protected, or private). After this
determination is made, the following possibilities exist for manually
changing the access level, in the derived class, of the inherited base
member as long as it is not inaccessible in the derived class:

1. It can be set no higher than what it was in the base
2. It can be set only to exactly what it was in the base
3. It can be set to anything

If it *is* inaccessible in the derived class, it must remain so.

I have seen statements in published books that 1 is the case. I have also
seen statements in published books that 2 is the case. Empirically, I have
observed that 3 is the case (as the results below indicate). Can somebody
please confirm that 3 is indeed what's permitted by the language?


#3, yes, _assuming_ that by 'base member' we mean an inherited data or
function member, not the base class sub-object.

In the standard this is mostly allowed by not disallowing it, but the
discussion of 'using'-declarations refers to 11.3 on access declarations
which simply says the access can be changed, and provides some examples of
that (access declarations are deprecated and seldom if ever used since
'using'-declarations do the same thing).

However, from a design level point of view it's generally not advisable to
change access levels in derived classes.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.