Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!borland.com!pete From: pete@borland.com (Pete Becker) Newsgroups: comp.lang.c++ Subject: Re: problem with ** and *& Message-ID: <1991Jun8.173601.4425@borland.com> Date: 8 Jun 91 17:36:01 GMT References: Distribution: comp Organization: Borland International Lines: 28 In article mfx@cs.tu-berlin.de (Markus Freericks) writes: >if a 'b' can be used in the same places as an 'a' and a pointer to b can >be used as a pointer to a; why doesn't this hold for a pointer to a >pointer to b?? The short answer is that the language defines a conversion from a class to one of its public bases, and a conversion of a pointer to a class to a pointer to one of its public bases, but does not do so for pointers to pointers to classes. So it just isn't allowed. Of course, the next question is, why isn't it allowed? Basically, because it would be very dangerous. For example: void func( Base **handle ) { *handle = new Base; } Derived *d; func( &d ); Now 'd' has been declared to be a pointer to Derived, but is, in fact, a pointer to Base. The compiler doesn't know this, though, and will be perfectly happy compiling code that applies member functions of Derived to the data pointed to by 'd'. Even calling virtual functions that don't exist in Base, which will almost certainly crash the program. There may occasionally be times where you know for sure that such a call is safe, and if one of those arises you can use a cast to tell the compiler that you are taking responsibility for any ill effects that may