Topic: Missing inheritance semantic
Author: Eyal Ben-David <eyal.ben-david@aks.com>
Date: 1998/03/15 Raw View
Robert M. M=FCnch wrote:
>=20
> Hi,
>
[...]=20
> Ok, it can be solved through the use of the :: operator but I have to
> type it each time and more worse, I have to make a define for the
> base-class name. Otherwise, if I would code it directly and the
> inheritance tree changes, I have to change all my derived classes in
> several places... not very efficient.
>=20
If you suspect that the inheritance tree is not solid enough you
can use the following:
template <class Base> class Derived : public Base
{
void f() { Base::f(); }
// ...
};
Now you have a 'Base' keyword in your class, and old code is not changed
when you replace the base class.
Eyal.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: rsailors@wyoming.com (Skip Sailors)
Date: 1998/03/16 Raw View
>>Is there any chance that we have a 'keyword' to refer to the
>>parent-class(es) in an abstract way?
<IMHO>
I alway felt that one of the beauties of the language was that
ambiguities in multiple inheritence are caught by the compiler; that
the programmer is constantly reminded that he is making a decision
about _exactly_ which behavior he wants when he resolves ambiguities.
As opposed to CLOS that keeps a complicated set of rules about
inheriting behavior that is so incomprehensible that the behavior we
get is a crap-shoot.
I think the brevity added to the language byt the 'inherited::' word
would be offset when programmers felt they no longer had to make
concious choices about behavior in inheritence situations.
</IMHO>
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Colin Rafferty <craffert@ml.com>
Date: 1998/03/17 Raw View
Hyman Rosen writes:
> David R Tribble <david.tribble@central.beasys.com> writes:
>> Members of class Der can now refer to members of the inherited
>> class Base by using an 'inherited::' prefix. Of course, this
>> doesn't work quite as well for multiple inheritance, although a
>> real 'inherited' keyword wouldn't work either.
> That's what people keep saying, but the proponents of such a
> keyword disagree. They want the inherited:: prefix to find a
> name in the base classes which would be the one selected if
> the current class did not itself define the name. If that
> choice is ambiguous, then there is an error, otherwise that
> name is used. Like this -
> struct A { virtual void a() { } virtual void z() { } };
> struct B { virtual void b() { } virtual void z() { } };
> struct C : A, B
> {
> void a() { inherited::a(); } // invokes A::a()
> void b() { inherired::b(); } // invokes B::b()
> void z() { inherited::z(); } // error - ambiguous
> };
I agree that keyword `inherited' would work with multiple inheritance.
However, so would this:
struct C_in : A, B {};
struct C : C_in
{
typedef C_in inherited;
void a() { inherited::a(); } // invokes A::a()
void b() { inherired::b(); } // invokes B::b()
void z() { inherited::z(); } // error - ambiguous
};
> The advantage of the keyword is not having to name the explicit
> base class whose function is being called.
The disadvantage is that it is yet one more piece of a large language
that people must learn.
--
Colin
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <uunet!jyacc!hymie@ncar.UCAR.EDU>
Date: 1998/03/17 Raw View
Colin Rafferty <craffert@ml.com> writes:
> I agree that keyword `inherited' would work with multiple inheritance.
>
> However, so would this:
>
> struct C_in : A, B {};
> struct C : C_in
> {
> typedef C_in inherited;
> void a() { inherited::a(); } // invokes A::a()
> void b() { inherired::b(); } // invokes B::b()
> void z() { inherited::z(); } // error - ambiguous
> };
>
> The disadvantage is that it is yet one more piece of a large language
> that people must learn.
Inserting extra classes like this carries a certain semantic weight of
its own; people will have to try to understand what they are for. Also,
if the classes involved have constructors, they must be replicated through
the intermediate classes, which is painful.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Barry Kleinman <barry@giga-net.com>
Date: 1998/03/17 Raw View
Allan D. Clarke wrote:
> We use this technique. I think though that there is a case
> where it does not work - in the constructor member initializer.
> To wit,
>
> CMyClass () : inherited (xxx), ...
> { ... }
>
> I haven't spent the time to chase down whether this is a compiler
> limitation or correct behavior.
This case works using Microsoft VC++ 5.0. You may have run into a compiler
limitation, or VC++ might have used a lenient interpretation of the draft
standard.
You can also use the base class typedef with most of Microsoft's annoying macros,
e.g.,
BEGIN_MESSAGE_MAP(MyClass, MyClass::BaseClass)
//{{AFX_MSG_MAP(MyClass)
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
assuming
class MyClass: public foo
{
public:
typedef foo BaseClass;
...
}
This saves a lot of error-prone editing if you decide to change MyClass's base
class from foo to something else. Since MFC doesn't support multiple inheritence
of message-handling classes, there's never a question of which base class to
typedef.
~~~~~~~~~~~~~~
Barry Kleinman
GigaNet, Inc.
2352 Main Street
Concord MA 01742-3828 USA
1-978-461-0402
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Brock" <peabody@npcinternational.com>
Date: 1998/03/11 Raw View
<<
>Is there any chance that we have a 'keyword' to refer to the
>parent-class(es) in an abstract way? Maybe this feature already exists
>(I haven't found it in C++ 3rd edition).
No, there is no 'keyword' to do what you want, but there is a simple
workaround.
class X {
public:
virtual void f() {}
};
class Y : public X {
typdef X parent;
public:
virtual void f() { parent::f();}
};
Brock Peabody
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: =?iso-8859-1?Q?Robert_M=2E_M=FCnch?= <Robert.M.Muench@SCRAP.de>
Date: 1998/03/12 Raw View
> -----Original Message-----
> From: Brock [SMTP:peabody@npcinternational.com]
> Posted At: Wednesday, March 11, 1998 10:32 PM
> Posted To: c++
> Conversation: Missing inheritance semantic
> Subject: Re: Missing inheritance semantic
>
> <<
> >Is there any chance that we have a 'keyword' to refer to the
> >parent-class(es) in an abstract way? Maybe this feature already
> exists
> >(I haven't found it in C++ 3rd edition).
>
> No, there is no 'keyword' to do what you want,
[Robert M. Muench] I know that's why asked if there will ever be a
chance for such a keyword.
> but there is a simple
> workaround.
[Robert M. Muench] That's what I'm doing now but it's a bit clumsy...
Robert M. Muench
SCRAP EDV-Anlagen GmbH, Karlsruhe, Germany
==> ask for PGP public-key <==
When do you want to reboot today?
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <david.tribble@central.beasys.com>
Date: 1998/03/13 Raw View
Robert M. M=FCnch wrote:
> > -----Original Message-----
> > From: Brock [SMTP:peabody@npcinternational.com]
> > Posted At: Wednesday, March 11, 1998 10:32 PM
> > Posted To: c++
> > Conversation: Missing inheritance semantic
> > Subject: Re: Missing inheritance semantic
> >
> > <<
> > >Is there any chance that we have a 'keyword' to refer to the
> > >parent-class(es) in an abstract way? Maybe this feature already
> > exists
> > >(I haven't found it in C++ 3rd edition).
> > No, there is no 'keyword' to do what you want,
> >
> [Robert M. Muench] I know that's why asked if there will ever be a
> chance for such a keyword.
>=20
> > but there is a simple
> > workaround.
> [Robert M. Muench] That's what I'm doing now but it's a bit clumsy...
If I understand the question, you're asking if there is a keyword
to use in a member functions of a derived class to access base
class members "in an abstract way".
Stroustrup mentions this "omission" from the language in
D&E (13.6). He gives a possible solution devised by Michael
Tiemann:
class Base
{
...
};
class Der: public Base
{
typedef Base inherited; // <--
...
};
Members of class Der can now refer to members of the inherited
class Base by using an 'inherited::' prefix. Of course, this
doesn't work quite as well for multiple inheritance, although a
real 'inherited' keyword wouldn't work either.
-- David R. Tribble, david.tribble@noSPAM.central.beasys.com --
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <uunet!jyacc!hymie@ncar.UCAR.EDU>
Date: 1998/03/15 Raw View
David R Tribble <david.tribble@central.beasys.com> writes:
> Members of class Der can now refer to members of the inherited
> class Base by using an 'inherited::' prefix. Of course, this
> doesn't work quite as well for multiple inheritance, although a
> real 'inherited' keyword wouldn't work either.
That's what people keep saying, but the proponents of such a
keyword disagree. They want the inherited:: prefix to find a
name in the base classes which would be the one selected if
the current class did not itself define the name. If that
choice is ambiguous, then there is an error, otherwise that
name is used. Like this -
struct A { virtual void a() { } virtual void z() { } };
struct B { virtual void b() { } virtual void z() { } };
struct C : A, B
{
void a() { inherited::a(); } // invokes A::a()
void b() { inherired::b(); } // invokes B::b()
void z() { inherited::z(); } // error - ambiguous
};
The advantage of the keyword is not having to name the explicit
base class whose function is being called.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Allan D. Clarke" <clarke_nospam_@ses.com>
Date: 1998/03/15 Raw View
David R Tribble wrote:
>
[snip]
>
> Stroustrup mentions this "omission" from the language in
> D&E (13.6). He gives a possible solution devised by Michael
> Tiemann:
>
> class Base
> {
> ...
> };
>
> class Der: public Base
> {
> typedef Base inherited; // <--
> ...
> };
>
[snip]
We use this technique. I think though that there is a case
where it does not work - in the constructor member initializer.
To wit,
CMyClass () : inherited (xxx), ...
{ ... }
I haven't spent the time to chase down whether this is a compiler
limitation or correct behavior.
--
: Allan Clarke : "All that is necessary for evil to abound is for :
: clarke_nospam@ses.com : good men to do nothing" -Edmond Burke :
: SES, Inc : http://www.ses.com/~clarke :
: Austin, Texas : 512/328-5544 512/327-6646(fax) :
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: =?iso-8859-1?Q?Robert_M=2E_M=FCnch?= <Robert.M.Muench@SCRAP.de>
Date: 1998/03/11 Raw View
Hi,
I recently have to write code where I'm missing a special inheritance
feature. I have a lot of functions which do exist in the base class and
in the derived class and which are declared as virtual. But from the
derived implementation I have to call the base-class implementation too,
to form a additive chain. I'm sure a lot of people know this problem.
Ok, it can be solved through the use of the :: operator but I have to
type it each time and more worse, I have to make a define for the
base-class name. Otherwise, if I would code it directly and the
inheritance tree changes, I have to change all my derived classes in
several places... not very efficient.
Is there any chance that we have a 'keyword' to refer to the
parent-class(es) in an abstract way? Maybe this feature already exists
(I haven't found it in C++ 3rd edition).
Robert M. Muench
SCRAP EDV-Anlagen GmbH, Karlsruhe, Germany
==> ask for PGP public-key <==
When do you want to reboot today?
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]