Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!jarthur!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: Re: What to do about generics and polymorphism in C++ Message-ID: <26108B02.2589@paris.ics.uci.edu> Date: 28 Mar 90 09:59:31 GMT References: <152@dumbcat.UUCP> <574@atcmpe.atcmp.nl> <153@dumbcat.UUCP> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 37 In article <153@dumbcat.UUCP> marc@dumbcat.UUCP (Marco S Hyman) writes: >In article <574@atcmpe.atcmp.nl> leo@atcmp.nl (Leo Willems) writes: > > From article <152@dumbcat.UUCP>, by marc@dumbcat.UUCP (Marco S Hyman): > > > void * generic; > > > D something; > > > B1 * b1 = &something; > > > B2 * b2; > > > > > > ++b1->i1; > > > generic = b1; // no adjustment > > > b2 = generic; // no adjustment > > > > If you apply a cast in the example does it work correct then? > > (If it works, is it legal or just luck? Andrew Koenig told me a long time > > ago it is legal, but that was in the 1.2 darkages, in which I still live :-)) > >G++ (the version I used to check the above example) does not require the >cast. My cfront 2.0 hasn't arived for this machine yet so I can't test it, g++ started out as a C compiler, and got changed into a C++ compiler later. You can still find occasional reminders of its lineage in places, like for instance in the fact that the type-checking & type-conversions have not been "hardened" to cfront standards yet. (Some people may prefer the looser typing that g++ provides.) g++ still allows you to assign a void* to other types of pointer variables. Cfront doesn't allow this without explicit casting. >... The moral is *don't* use void* for generics. I concur. // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.