home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
- From: sakkinen@jyu.fi (Markku Sakkinen)
- Subject: Re: Casting to an object of a derived class
- Message-ID: <1992Nov10.103449.18958@jyu.fi>
- Organization: University of Jyvaskyla, Finland
- References: <VANDER.92Nov2153247@vancouver.stars.flab.Fujitsu.co.jp> <rmartin.721099675@thor>
- Date: Tue, 10 Nov 1992 10:34:49 GMT
- Lines: 37
-
- In article <rmartin.721099675@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- > ...
- >This is one of the difficulties with contravariant return types. It
- >would sometimes be very nice if a member function could return a
- >pointer or reference to the most derived object, rather than to the
- >base. However, the language does not support this feature.
-
- Of course, if the return type is a pointer or reference to a class,
- the derived-class function _can_ return a reference or pointer
- to a derived-class object. Virtual functions will work correctly.
- The big problem remains that only members declared in the original
- return-type class can be denoted.
-
- >It will, soon, support covariant return types, but these will require
- >that each derived class repeat the function declaration with the new
- >return type.
-
- Of course they must do that: how should the compiler or anybody
- know otherwise that there is supposed to be a new return type?
-
- Even if this becomes true, the above problem goes away only in the case
- where it is statically known that indeed the function of the derived class
- will be invoked. The absence of run-time type information makes
- covariant return types a less powerful feature in C++ than in other
- OO languages.
-
- > ...
-
- ----------------------------------------------------------------------
- Markku Sakkinen (sakkinen@jytko.jyu.fi)
- SAKKINEN@FINJYU.bitnet (alternative network address)
- Department of Computer Science and Information Systems
- University of Jyvaskyla (a's with umlauts)
- PL 35
- SF-40351 Jyvaskyla (umlauts again)
- Finland
- ----------------------------------------------------------------------
-