472,986 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Changing access levels of inherited base members

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
1 4265
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Siemel Naran | last post by:
Do using declarations respect private, protected, public access levels? class A { public: void f(); private: void f(int); }; class B : public A {
1
by: Rene Blom | last post by:
Hello, i am trying several times to get my access '97 D-base in a access 2002 D-base but every time I get a mention that the D-bade is closed en wil be repared. Help please
6
by: Edward Diener | last post by:
Since a C++ using declaration isn't allowed in MC++, is there a way to specify that a property, method, event, or field's access can be changed in a derived class, ie. is protected in one class and...
0
by: Parvez | last post by:
HI How to connect MS ACCESS in Netwaork base VB6.0 Programme from server I AM DEVLOPING A EMPLOYE ATTANEDENS RECORD PROJECT IN THIS I AM USING VB6.0 AND MS ACCESS AND WINDOEW XP IN MY PROJECT...
13
by: dragoncoder | last post by:
Consider the following code #include <iostream> class Base { public: virtual void say() { std::cout << "Base" << std::endl; } }; class Derived: public base {
2
by: pkpatil | last post by:
Hi, Can a private composite object in a class access private or protected members of base class? For e.g. class composite { void memberFunction(); };
0
by: lovecreatesbea... | last post by:
I) List of synthesized class members By default, a class gets 1. default construction 2. copy construction 3. assignment 4. . (dot) 5. , (comma) 6. destruction
3
by: ukrutter | last post by:
Any help would be greatfully recieved here! I'll try and explain the situation here... I have a database in Access, which is in essence a booking system. I am using VB6 to link to this database....
4
by: RinKaMeAri | last post by:
Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method():
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.