473,415 Members | 1,545 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,415 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 4312
* 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.