Topic: Protected base classes
Author: mneerach@c.inf.ethz.ch (Matthias Ulrich Neeracher)
Date: 30 Aug 90 13:14:09 GMT Raw View
Recently, I tried to use a protected base class, like this:
class A {
...
};
class B:protected A {
...
};
To my surprise, my compiler (based on CFront 2.0) refused to compile this.
The ARM doesn't seem to be clear about this: The syntax seems to allow it,
but the text and examples don't mention it.
My question is: If protected base classes are indeed illegal, why are they
and what speaks against adding them to C++ ?
I hope this question is not inappropriate for this newsgroup.
Matthias
-----
Matthias Neeracher mneerach@inf.ethz.ch
"I wouldn't recommend sex, drugs or insanity for everyone,
but they've always worked for me" -- Hunter S. Thompson
Author: bs@alice.UUCP (Bjarne Stroustrup)
Date: 31 Aug 90 02:54:04 GMT Raw View
The summaries say it all.
Author: hansen@pegasus.ATT.COM (Tony L. Hansen)
Date: 31 Aug 90 18:32:06 GMT Raw View
< Recently, I tried to use a protected base class, like this:
< class A { ... };
< class B: protected A { ... };
< To my surprise, my compiler (based on CFront 2.0) refused to compile this.
< The ARM doesn't seem to be clear about this: The syntax seems to allow it,
< but the text and examples don't mention it.
< My question is: If protected base classes are indeed illegal, why are they
< and what speaks against adding them to C++ ?
The introduction of protected base classes occurred this year as part of the
1990 C++ definition. The AT&T 2.1 C++ Reference Manual, and subsequently The
Annotated C++ Reference Manual (E&S), documents its introduction.
However, NO compiler currently implements protected base classes, not even
AT&T's 2.1. Also, the exact semantics have NOT been cast in stone, although
it's unlikely that they will differ much from the following description:
The visibility of the members of a base class are "capped" at the level of
the access specifier given for the base class. For the following example:
class base
{
public: int bpublic;
private: int bprivate;
protected:int bprotected;
};
class derived : class derived : class derived :
public base protected base private base
{ { {
... ... ...
}; }; };
the visibility of the different base members are adjusted as follows for the
various members of base using the different access specifications:
access spec: public protected private
----------------------------------------------------------------
bpublic: public protected private
bprotected: protected protected private
bprivate: not accessible not accessible not accessible
I hope this helps.
< I hope this question is not inappropriate for this newsgroup.
I'd say it's perfectly appropriate for this newsgroup.
Tony Hansen
att!pegasus!hansen, attmail!tony
hansen@pegasus.att.com
Author: jimad@microsoft.UUCP (Jim ADCOCK)
Date: 4 Sep 90 18:52:59 GMT Raw View
In article <5026@neptune.inf.ethz.ch> mneerach@c.inf.ethz.ch (Matthias Ulrich Neeracher) writes:
>
>class B:protected A {
> ...
>};
>
>To my surprise, my compiler (based on CFront 2.0) refused to compile this.
>The ARM doesn't seem to be clear about this: The syntax seems to allow it,
>but the text and examples don't mention it.
Existing compilers are not reliable indicators of the fine-grained details
of the standardization effort. E&S is. Compilers claiming "2.1"
compatibility may be pretty close to E&S.
>My question is: If protected base classes are indeed illegal, why are they
>and what speaks against adding them to C++ ?
My understanding is that protected base classes will be allowed.
Unfortunately, I cannot find the appropriate reference in E&S.
[Though I'm sure I read it somewhere....]