Path: utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!jarthur!nntp-server.caltech.edu!woody From: woody@nntp-server.caltech.edu (William Edward Woody) Newsgroups: comp.sys.mac.programmer Subject: Re: C++ vs Think C 4.0 Question Message-ID: <1990Nov29.181707.25001@nntp-server.caltech.edu> Date: 29 Nov 90 18:17:07 GMT References: <1990Nov27.040144.27236@cunixf.cc.columbia.edu> <1990Nov27.163703.1323@actrix.gen.nz> Organization: California Institute of Technology, Pasadena Lines: 87 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.