From 673147967415501427 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,83495c7465612f38 X-Google-Attributes: gidf78e5,public From: "news.xs4all.nl" Subject: Re: Reference to base class pointer Date: 1999/05/20 Message-ID: <7hvjj1$s57$1@news1.xs4all.nl>#1/1 X-Deja-AN: 479841878 X-NNTP-Posting-Host: dc2-modem1031.dial.xs4all.nl Approved: stephen.clamage@sun.com (comp.std.c++) References: <37428FB3.5DC7@eae.com> X-UID: 0000000001 X-Status: $$$T X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: abuse@xs4all.nl X-Trace: news1.xs4all.nl 927158689 28839 194.109.132.7 (20 May 1999 00:04:49 GMT) Organization: XS4ALL Internet BV NNTP-Posting-Date: 20 May 1999 00:04:49 GMT Newsgroups: comp.std.c++ Originator: clamage@taumet The same problem holds for converting a Derived ** to a Base **. This is not allowed for the following reason: class Base { }; class Derived1 : public Base { }; class Derived2 : public Base { }; void foo() { Derived1 d1; Derived1 *p1 = &d1; Derived2 d2; Derived2 *p2 = &d2; Base **pp = &p1; /* convert Derived1** to Base**, not allowed */ *pp = p2; /* convert Derived2* to Base *, allowed */ /* At this point p1 which is a Derived1 pointer is pointing to a Derived2 variable. Possible disaster!! */ } Your example is simply a variation of the same principle. Silvio Bierman Gernot wrote in message <37428FB3.5DC7@eae.com>... >I've just changed some existing code and abandonded using pointers to >pointers. Instead I'm using references to pointers now, which greatly >improves readability. But still my compiler keeps telling me that it >cannot cast a reference to a pointer to class Derived to a reference to >a Base class pointer. >Simple question: Is that standard-conforming behaviour or can I hope for >a new compiler version? > >Just for clarity, the essential code: > >class Base >{ >}; > >class Derived : public Base >{ >}; > >void foo( Base*& rpBase ); > >int main() >{ > Derived* pDerived = NULL; > foo( pDerived ); // This is the error! >... [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]