Re: Am I missing something in private inheritance?
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 01/11/05
- Next message: J Swift: "Re: School..."
- Previous message: Mike Wahler: "Re: School..."
- In reply to: Alf P. Steinbach: "Re: Am I missing something in private inheritance?"
- Next in thread: Ioannis Vranos: "Re: Am I missing something in private inheritance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 10 Jan 2005 19:01:01 -0500
"Alf P. Steinbach" <alfps@start.no> wrote...
>* Victor Bazarov:
>>
>> So, Alf, what's your take on it? I say, since the default c-tor of the
>> virtual base class is public, it should be accessible. Do you think
>> otherwise?
>
> In part I do. I disagree strongly with the justification, it does not
> make
> sense to me. Regarding the conclusion, for the specific case of default
> constructor, I do not know.
>
>
>> Could you give justification (from the Standard) why it would
>> not be accessible?
>
> Private inheritance.
>
> It gives non-accessibility for anything except the generated default
> constructor.
>
> For the generated default constructor, I do not know, but as earlier
> stated I strongly suspect a compiler bug in three compilers, namely
> Comeau, GNU
> and MSVC.
>
> For example, the following code does _not_ compile with MSVC, which is as
> it
> should be IMHO:
>
>
> class HiddenSealBaseClass
> {
> public:
> HiddenSealBaseClass() { }
> };
>
> class Sealed: virtual HiddenSealBaseClass
> {};
>
> class SomeClass: Sealed
> {
> SomeClass(): HiddenSealBaseClass() {}
> // Whatever
> };
>
> int main()
> {
> SomeClass obj;
> }
>
>
> vc_project.cpp(22): error C2248: 'SomeClass::SomeClass' : cannot access
> private
> member declared in class 'SomeClass'
This is where I am puzzled to the extreme. It seems that SomeClass has
less access to 'HiddenSealBaseClass' than anybody else. That goes against
_any_ possible role an access specifier is supposed to play.
Now, here is another example where it would be really bad.
I have two classes, B and D. B has a public default constructor (whether
it's generated or user-defined shouldn't matter). In D I have an object
of type B, which is created using all default ways (no mention of it in
the D's constructor initialiser list). Now, I decide to inherit [some
functionality] from a third-party class C, which at the time virtually and
publicly derived from B. My program is well-formed. Now, the third party
decides to change public inheritance to private. BAM! Suddenly, my
program's well-formedness depends on whether C is derived from B and how.
What?!! No, sorry, B's constructor is public and it should be accessible
_no_matter_ who and how intends to use it.
The main point of private inheritance is to prevent automatic conversions
from the derived to base. When the base class is used/instantiated without
any intervening derived members (and that's the case in virtual inheritance
among others), IOW, directly, the access used is the one that's specified
by the base class _itself_.
Victor
- Next message: J Swift: "Re: School..."
- Previous message: Mike Wahler: "Re: School..."
- In reply to: Alf P. Steinbach: "Re: Am I missing something in private inheritance?"
- Next in thread: Ioannis Vranos: "Re: Am I missing something in private inheritance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|