[comp.sys.mac.programmer] C++ vs Think C 4.0 Question

jtt@cunixd.cc.columbia.edu (James T. Tanis) (11/27/90)

I'm interested in learning c++, but in reading various stuff about it, I
have
yet to encounter the "inherited" scope specifier, ubiquitous in TCL
programs. Is there, in fact, no way in 'real' c++ to just call the same
function in a base class?

I can see how this migh cause some trouble with multiple inheritance, also,
I know that you can call a base class function by specifying it's name:
class x: public y { ..... };

and later, in a method of x

y::method();

but what I want to know is if

inherited::method();

will accomplish the same thing.

THanks!

-JT

Bruce.Hoult@bbs.actrix.gen.nz (11/28/90)

In article <1990Nov27.040144.27236@cunixf.cc.columbia.edu> jtt@cunixd.cc.columbia.edu (James T. Tanis) writes:
> I'm interested in learning c++, but in reading various stuff about it, I
> have
> yet to encounter the "inherited" scope specifier, ubiquitous in TCL
> programs. Is there, in fact, no way in 'real' c++ to just call the same
> function in a base class?

Correct.  Standard C++ doesn't have the "inherited" keyword.  Apple have added
it to their MPW C++ compiler, but only for objects derived from the special
base class "PascalObject".  They didn't allow it in general useage because
they wanted to "avoid making gratuitous changes to C++".

I'd like to see it as well.

woody@nntp-server.caltech.edu (William Edward Woody) (11/30/90)

In article <1990Nov27.163703.1323@actrix.gen.nz> Bruce.Hoult@bbs.actrix.gen.nz writes:
>In article <1990Nov27.040144.27236@cunixf.cc.columbia.edu> jtt@cunixd.cc.columbia.edu (James T. Tanis) writes:
>> I'm interested in learning c++, but in reading various stuff about it, I
>> have
>> yet to encounter the "inherited" scope specifier, ubiquitous in TCL
>> programs. Is there, in fact, no way in 'real' c++ to just call the same
>> function in a base class?
>
>Correct.  Standard C++ doesn't have the "inherited" keyword.  Apple have added
>it to their MPW C++ compiler, but only for objects derived from the special
>base class "PascalObject".  They didn't allow it in general useage because
>they wanted to "avoid making gratuitous changes to C++".
>
>I'd like to see it as well.


Actually, if you have the following declarations:

	class TObject1 {
	    public:
		virtual void foo();
	};

	class TObject2: public TObject1 {
	    public:
			void foo();
	};

the following is legal and does what you want in both MPW C++ and Turbo C++
on the IBM PC (don't ask why I'm using a PC; it's a horrible story):

	void TObject2::foo()
	{
	    TObject1::foo();		/* Will call TObject1::foo() */
	}

The extension keyword 'inherited' simply did the following:

	void TObject2::foo()
	{
	    inherited::foo();		/* Will call TObject1::foo() */
	}

The problem with this keyword is when you have multiple inheritance.  For
example:

	class TObject1 {
	    public:
		virtual void foo();
	};

	class TObject2 {
	    public:
		virtual void foo();
	};

	class TObject3: public TObject1, public TObject2 {
	    public:
			void foo();
	};

and in TObject3::foo() you say:

	void TObject3::foo()
	{
	    inherited::foo();
	}

do you mean TObject1::foo() or TObject2::foo()?

C++ requires that you expressly indicate which function you are calling.
This is only a minor price to pay, IMHO, for the value of multiple
inheritance.

				-- Bill

Disclamer:  none of the code above was tested, but the examples were taken
from memory of actual working code.  Further, I don't know why you
would ever want to do the second example above, but I suppose it can
come up in actual code.  Your milege will vary.  Do not remove back
panel; no serviceable parts inside.

-- 
	William Edward Woody		   | Disclamer:
USNAIL	P.O.Box 50986; Pasadena, CA 91115  |
EMAIL	woody@tybalt.caltech.edu	   | The useful stuff in this message
ICBM	34 08' 44''N x 118 08' 41''W	   | was only line noise. 

philip@pescadero.Stanford.EDU (Philip Machanick) (11/30/90)

In article <1990Nov29.181707.25001@nntp-server.caltech.edu>, woody@nntp-server.caltech.edu (William Edward Woody) writes:
|> In article <1990Nov27.163703.1323@actrix.gen.nz> Bruce.Hoult@bbs.actrix.gen.nz writes:
|> >In article <1990Nov27.040144.27236@cunixf.cc.columbia.edu> jtt@cunixd.cc.columbia.edu (James T. Tanis) writes:
|> >> I'm interested in learning c++, but in reading various stuff about it, I
|> >> have
|> >> yet to encounter the "inherited" scope specifier, ubiquitous in TCL
|> >> programs. Is there, in fact, no way in 'real' c++ to just call the same
|> >> function in a base class?
|> >Correct.  Standard C++ doesn't have the "inherited" keyword.  Apple have added
|> >it to their MPW C++ compiler, but only for objects derived from the special
|> >base class "PascalObject".  They didn't allow it in general useage because
|> >they wanted to "avoid making gratuitous changes to C++".
|> >
|> >I'd like to see it as well.
|> Actually, if you have the following declarations:
[example]
|> The problem with this keyword is when you have multiple inheritance.  For
|> example:
[example]
|> C++ requires that you expressly indicate which function you are calling.
|> This is only a minor price to pay, IMHO, for the value of multiple
|> inheritance.
There is a discussion of this going on in comp.lang.c++. Multiple inheritance
makes it impossible to implement "inherited" in cases where there might be
ambiguity as to the intended base class. However, this ambiguity issue
comes up in other contexts in C++ as well. It doesn't mean the feature couldn't
be implemented, only that it couldn't always be used.
-- 
Philip Machanick
philip@pescadero.stanford.edu

Bruce.Hoult@bbs.actrix.gen.nz (11/30/90)

In article <1990Nov29.181707.25001@nntp-server.caltech.edu> woody@nntp-server.caltech.edu (William Edward Woody) writes:
> In article <1990Nov27.163703.1323@actrix.gen.nz> Bruce.Hoult@bbs.actrix.gen.nz writes:
> >Correct.  Standard C++ doesn't have the "inherited" keyword.  Apple have added
> >it to their MPW C++ compiler, but only for objects derived from the special
> >base class "PascalObject".  They didn't allow it in general useage because
> >they wanted to "avoid making gratuitous changes to C++".
> 
> Actually, if you have the following declarations:
> 
> [explanation of how to specify the base class explicitly]
> 
> The problem with this keyword is when you have multiple inheritance.  For
> example:
>
> [example of a multiple inheritance hierachy]
> 
> and in TObject3::foo() you say:
> 
> 	void TObject3::foo()
> 	{
> 	    inherited::foo();
> 	}
> 
> do you mean TObject1::foo() or TObject2::foo()?
> 
> C++ requires that you expressly indicate which function you are calling.
> This is only a minor price to pay, IMHO, for the value of multiple
> inheritance.
> 
> 				-- Bill

Well, thanks for telling me stuff I already knew :-)

The fact that inherited can sometimes be ambiguous in multiple inheritance
is no reason to not allow it.  If your TObject3, above, had not defined
foo() at all then there would have been the possibility of a client of the
class attempting to call foo() -- and ambiguity rears its head again!

The language specification says that it is OK to have a potential ambiguity
and it is only when an *actual* ambiguous use is made that an error occurs.

Following the same principle, "inherited" could be allowed even in multiple
inheritance with the compiler warning of ambiguous usage.

-- Bruce Hoult
   Bruce.Hoult@bbs.actrix.gen.nz