home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16034 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.7 KB  |  43 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
  3. From: sakkinen@jyu.fi (Markku Sakkinen)
  4. Subject: Re: Wanted: Example of Contravariance
  5. Message-ID: <1992Nov10.100614.17265@jyu.fi>
  6. Organization: University of Jyvaskyla, Finland
  7. References: <1992Nov2.111322.1@happy.colorado.edu> <rmartin.721098936@thor>
  8. Date: Tue, 10 Nov 1992 10:06:14 GMT
  9. Lines: 32
  10.  
  11. In article <rmartin.721098936@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  12. > ...
  13. >Notice that the arguments of the two 'f' functions are the same.  This
  14. >is "contravariance", since the argument does not (contra) vary with
  15. >the class type.  
  16.  
  17. You are mistaken about the terminology.
  18. Contravariance means that the class of an argument for a function
  19. redefined in a derived class may be a base class of the same
  20. argument's class in the original function.
  21. ('Contra' means that the subtype relationship between the arguments
  22. is opposite to that between the classes in which the functions are defined.)
  23. C++, as defined by the ARM has _neither_ contra- nor covariance.
  24.  
  25. >However, the return values are "covariant" since they do (co) vary
  26. >with the class type.
  27. >
  28. >Although covariant return types have been accepted into the language
  29. >definition, I don't think they are accepted by many of the compiler
  30. >out ther right now.  Contravariant arguments are mandatory in C++.
  31.  
  32. Which language definition?
  33.  
  34. ----------------------------------------------------------------------
  35. Markku Sakkinen (sakkinen@jytko.jyu.fi)
  36.        SAKKINEN@FINJYU.bitnet (alternative network address)
  37. Department of Computer Science and Information Systems
  38. University of Jyvaskyla (a's with umlauts)
  39. PL 35
  40. SF-40351 Jyvaskyla (umlauts again)
  41. Finland
  42. ----------------------------------------------------------------------
  43.