Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!yale!think!samsung!uunet!mcsun!hp4nl!kunivv1!atcmpe!leo From: leo@atcmp.nl (Leo Willems) Newsgroups: comp.lang.c++ Subject: Re: What to do about generics and polymorphism in C++ Message-ID: <576@atcmpe.atcmp.nl> Date: 27 Mar 90 21:39:00 GMT References: <574@atcmpe.atcmp.nl> Organization: AT Computing, Nijmegen, The Netherlands Lines: 53 From article <574@atcmpe.atcmp.nl>, by leo@atcmp.nl (Leo Willems): > From article <152@dumbcat.UUCP>, by marc@dumbcat.UUCP (Marco S Hyman): stuff deleted >> Doesn't always work. In the case of multiple inheritance pointer adjustment >> void * a different type than was placed in the void pointer, things break. > > Stuff deleted > >> void * generic; >> D something; >> B1 * b1 = &something; >> B2 * b2; >> >> ++b1->i1; >> generic = b1; // no adjustment >> b2 = generic; // no adjustment > > Under C++ 1.2 the last sentence will give a "bad assigment type" error. > As I understand it, assignment to void* must be casted in C++ (which > is different in ANSI-C) thereby bringing type-information back. > Oops, I spoke to soon: casting a B1* to B2* is nonsense (most of the time) b2 = (B2*) generic; // most of the time wrong. However, even if probably wrong, leaving out the cast will genete a compiler error. What I had in mind (and of which I think is legal in C++ 1.2 and 2.0): class b{ ... }; class bd : b { .... }; bd bd_o; void *g; b *bp; g = &bd_o; bp = (b*) g; // not casting here will give an error Sorry about that. Leo Willems Internet: leo@atcmp.nl AT Computing UUCP: mcvax!hp4nl!kunivv1!atcmpe!leo P. O. Box 1428 6501 BK Nijmegen Phone: +31-80-566880 The Netherlands Fax: +31-80-555887 Leo.