Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!att!news.cs.indiana.edu!maytag!watmath!watmsg.waterloo.edu!gjditchfield From: gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) Newsgroups: comp.lang.c++ Subject: Re: typesafe downward casting and contravariance Message-ID: <1991Apr10.145811.16061@watmath.waterloo.edu> Date: 10 Apr 91 14:58:11 GMT References: <9104091317.AA16916@ucbvax.Berkeley.EDU> Sender: news@watmath.waterloo.edu (News Owner) Organization: University of Waterloo Lines: 20 In article <9104091317.AA16916@ucbvax.Berkeley.EDU> schweitz@lexvmc.vnet.ibm.com ("Eric Schweitz") writes: > ... Let's assume that the function sin() is contravariant... > > int sin (int); > float sin (float); > complex sin (complex); That is not contravariance. In contravariance, the types of arguments and the return type change in the opposite way (hence the prefix "contra"). struct adam { ... }; struct bob: public adam { virtual bob* contra_f(bob*); virtual bob* co_f(bob*); }; struct chuck: public bob { chuck* contra_f(adam*); // contravariant redefinition chuck* co_f(chuck*); // covariant redefinition };