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: Wanted: Example of Contravariance
- Message-ID: <1992Nov10.100614.17265@jyu.fi>
- Organization: University of Jyvaskyla, Finland
- References: <1992Nov2.111322.1@happy.colorado.edu> <rmartin.721098936@thor>
- Date: Tue, 10 Nov 1992 10:06:14 GMT
- Lines: 32
-
- In article <rmartin.721098936@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- > ...
- >Notice that the arguments of the two 'f' functions are the same. This
- >is "contravariance", since the argument does not (contra) vary with
- >the class type.
-
- You are mistaken about the terminology.
- Contravariance means that the class of an argument for a function
- redefined in a derived class may be a base class of the same
- argument's class in the original function.
- ('Contra' means that the subtype relationship between the arguments
- is opposite to that between the classes in which the functions are defined.)
- C++, as defined by the ARM has _neither_ contra- nor covariance.
-
- >However, the return values are "covariant" since they do (co) vary
- >with the class type.
- >
- >Although covariant return types have been accepted into the language
- >definition, I don't think they are accepted by many of the compiler
- >out ther right now. Contravariant arguments are mandatory in C++.
-
- Which language definition?
-
- ----------------------------------------------------------------------
- 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
- ----------------------------------------------------------------------
-