Topic: C++ proposals


Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/03
Raw View
In article <Pine.SUN.3.91.970103084550.10249A-100000@catsrv0> ben.elliston@compucat.com.au writes:
>> > If a have a class, let's say CSon, derived from class CGrandDad, and
>> > I want to redefine class CSon to be derived from CDad, which is derived
>> > from CGrandDad, I have to change all member functions that call the
>> > bass class, like CGrandDad::foe(); to CDad::foe();
>
>> > In Java, this is more elegant; they have a keyword for it. I believe
>> > it is called 'super'. So I could write super::foe(); to call the bass
>> > class function. Because if I forget to change one of the CGrandDad::
>> > calls, I am calling the base class of the bass class, bypassing the
>> > single bass class. This could cause erratic code.
>
>I can see the merits of this . . I've fallen into this trap myself.  The
>only problem here is that Java does not support multiple inheritence, so
>when you say `super', you know which class you are referring to.
>
>I don't see multiple inheritence disappearing from C++, but it would be
>nice to allow a keyword like `super' to be used in the context where only
>one parent class exists.  I wonder if there are any gotchas to this
>notion?

None really besides the obvious with MI.  And it would be easy enough
to implement (actually, at least Apple has done so at least once upon a time).
The reason we don't have this though it that it was deemed possible
to do this w/o an extension, via a typedef.  This does require the
burden upon the programmer though.  OTOH, this is perhaps exactly
what's wanted for such control.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421



Author: Mike Crowe <mac@stone.dcs.warwick.ac.uk>
Date: 1997/01/06
Raw View
Ben Elliston <bje@compucat.com.au> writes:

> > > If a have a class, let's say CSon, derived from class CGrandDad, and
> > > I want to redefine class CSon to be derived from CDad, which is derived
> > > from CGrandDad, I have to change all member functions that call the
> > > bass class, like CGrandDad::foe(); to CDad::foe();

> > > In Java, this is more elegant; they have a keyword for it. I believe
> > > it is called 'super'. So I could write super::foe(); to call the bass
> > > class function. Because if I forget to change one of the CGrandDad::
> > > calls, I am calling the base class of the bass class, bypassing the
> > > single bass class. This could cause erratic code.

[snip]

> I don't see multiple inheritence disappearing from C++, but it would be
> nice to allow a keyword like `super' to be used in the context where only
> one parent class exists.  I wonder if there are any gotchas to this
> notion?

A keyword like 'super' would have the advantage that it could be deemed
ambiguous when multiple inheritance is used. For example, take the class:

class D : public A
{
  ...
  void dump() { dumpme(); super::dump(); }
};

Now suppose that some time later I need to make class D derive from both
class A and class B. If super is a keyword defined as above then it becomes
ambiguous and I must then resolve the ambiguity explicitly, a good
thing. If a typedef were used then this change would cause no errors at
compile time and potentially introduce bugs. (Although, admittedly the
typedef would probably be the first thing in the class definition and
therefore obvious that it should be changed).

I must admit though that apart from saving a bit of typing and this ability
to notice ambiguity a super keyword has little benefit.
--
Mike Crowe <mac@fysh.org>, University of Warwick, Coventry, UK.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/01/06
Raw View
Ben Elliston <bje@compucat.com.au> writes:

|>  > > If a have a class, let's say CSon, derived from class CGrandDad, and
|>  > > I want to redefine class CSon to be derived from CDad, which is derived
|>  > > from CGrandDad, I have to change all member functions that call the
|>  > > bass class, like CGrandDad::foe(); to CDad::foe();
|>
|>  > > In Java, this is more elegant; they have a keyword for it. I believe
|>  > > it is called 'super'. So I could write super::foe(); to call the bass
|>  > > class function. Because if I forget to change one of the CGrandDad::
|>  > > calls, I am calling the base class of the bass class, bypassing the
|>  > > single bass class. This could cause erratic code.
|>
|>  I can see the merits of this . . I've fallen into this trap myself.  The
|>  only problem here is that Java does not support multiple inheritence, so
|>  when you say `super', you know which class you are referring to.
|>
|>  I don't see multiple inheritence disappearing from C++, but it would be
|>  nice to allow a keyword like `super' to be used in the context where only
|>  one parent class exists.  I wonder if there are any gotchas to this
|>  notion?

There's an easy solution in the case of single inheritance: use a
typedef.  The real advantage of such a solution (integrated into the
language) is precisely in the case of multiple inheritance.

Very early in the standardization effort, there was a proposal for
this.  (I think the keyword was "inherited".)  It was rejected because
it is so easy to simulate.  At the time, I don't think that the case
concerning multiple inheritance was really considered.  I don't think
that there was ever a proposal after the argument involving multiple
inheritance was presented.  At the time, it was also fairly late, and it
is certainly too late now to consider such a proposal.

--
James Kanze         home:     kanze@gabi-soft.fr        +33 (0)3 88 14 49 00
                    office:   kanze@vx.cit.alcatel.fr   +33 (0)1 69 63 14 54
GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
       -- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "F. van Leeuwen" <fvl@iaehv.nl>
Date: 1997/01/06
Raw View
James Kanze <james-albert.kanze@vx.cit.alcatel.fr> wrote in article
>
> Very early in the standardization effort, there was a proposal for
> this.  (I think the keyword was "inherited".)  It was rejected because
> it is so easy to simulate.  At the time, I don't think that the case
> concerning multiple inheritance was really considered.  I don't think
> that there was ever a proposal after the argument involving multiple
> inheritance was presented.  At the time, it was also fairly late, and it
> is certainly too late now to consider such a proposal.
>

Well, may be we are in time for the next wave of C++ standardisation,
together with the 'null' issue.

Frank.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Matt Seitz <mseitz@meridian-data.com>
Date: 1997/01/06
Raw View
Greg Comeau wrote:
> The reason we don't have this though it that it was deemed possible
> to do this w/o an extension, via a typedef.

For details about this, see THE C++ PROGRAMMING LANGUAGE 2nd Edition,
Section 6.5.2 (Derived Classes:  Multiple Inheritence:  Ambiguity
Resolution).  Also see THE DESIGN AND EVOLUTION OF C++, Section 13.6
(Class Concept Refinements:  "Inherited::").
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/07
Raw View
In article <rf5k9pr6r87.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>Ben Elliston <bje@compucat.com.au> writes:
>
>|>  > > If a have a class, let's say CSon, derived from class CGrandDad, and
>|>  > > I want to redefine class CSon to be derived from CDad, which is derived
>|>  > > from CGrandDad, I have to change all member functions that call the
>|>  > > bass class, like CGrandDad::foe(); to CDad::foe();
>|>
>|>  > > In Java, this is more elegant; they have a keyword for it. I believe
>|>  > > it is called 'super'. So I could write super::foe(); to call the bass
>|>  > > class function. Because if I forget to change one of the CGrandDad::
>|>  > > calls, I am calling the base class of the bass class, bypassing the
>|>  > > single bass class. This could cause erratic code.
>|>
>|>  I can see the merits of this . . I've fallen into this trap myself.  The
>|>  only problem here is that Java does not support multiple inheritence, so
>|>  when you say `super', you know which class you are referring to.
>|>
>|>  I don't see multiple inheritence disappearing from C++, but it would be
>|>  nice to allow a keyword like `super' to be used in the context where only
>|>  one parent class exists.  I wonder if there are any gotchas to this
>|>  notion?
>
>There's an easy solution in the case of single inheritance: use a
>typedef.  The real advantage of such a solution (integrated into the
>language) is precisely in the case of multiple inheritance.
>
>Very early in the standardization effort, there was a proposal for
>this.  (I think the keyword was "inherited".)  It was rejected because
>it is so easy to simulate.  At the time, I don't think that the case
>concerning multiple inheritance was really considered.  I don't think
>that there was ever a proposal after the argument involving multiple
>inheritance was presented.  At the time, it was also fairly late, and it
>is certainly too late now to consider such a proposal.

The MI case was always considered/known.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Ben Elliston <bje@compucat.com.au>
Date: 1997/01/02
Raw View
> > If a have a class, let's say CSon, derived from class CGrandDad, and
> > I want to redefine class CSon to be derived from CDad, which is derived
> > from CGrandDad, I have to change all member functions that call the
> > bass class, like CGrandDad::foe(); to CDad::foe();

> > In Java, this is more elegant; they have a keyword for it. I believe
> > it is called 'super'. So I could write super::foe(); to call the bass
> > class function. Because if I forget to change one of the CGrandDad::
> > calls, I am calling the base class of the bass class, bypassing the
> > single bass class. This could cause erratic code.

I can see the merits of this . . I've fallen into this trap myself.  The
only problem here is that Java does not support multiple inheritence, so
when you say `super', you know which class you are referring to.

I don't see multiple inheritence disappearing from C++, but it would be
nice to allow a keyword like `super' to be used in the context where only
one parent class exists.  I wonder if there are any gotchas to this
notion?

bje

--
Ben Elliston    E-mail: ben.elliston@compucat.com.au
Compucat Research Pty Limited  WWW: <http://www.compucat.com.au>
Fyshwick ACT Australia



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]