From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexandre Oliva To: Michael Lee Cc: egcs-bugs@cygnus.com Subject: Re: bug report Date: Fri, 20 Nov 1998 14:08:00 -0000 Message-id: References: <36550100.769A3CBB@ms.com> X-SW-Source: 1998-11/msg00584.html List-Id: On Nov 20, 1998, Michael Lee wrote: > class Derived: virtual public Base { > cout << reinterpret_cast(dp)->status() << endl; > Segmentation Fault (core dumped) You want dynamic_cast, not reinterpret_cast. reinterpret_cast just tells to compiler to interpret the Base* as if it were a pointer to Derived*, *without* performing the needed conversions. You'll also have to make the base class polymorphic, by declaring some of its methods virtual (e.g., the destructor) > If you take out virtual from and change it to "class Derived: public > Base {", it works. It works by chance, just because the offset of the Base class is zero in this case. -- Alexandre Oliva http://www.dcc.unicamp.br/~oliva aoliva@{acm.org} oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org.au} Universidade Estadual de Campinas, SP, Brasil