473,289 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 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 4303
* 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():
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.