by Tony Delroy <tony_in_da_uk@[EMAIL PROTECTED]
>
Apr 30, 2008 at 10:27 AM
On Apr 30, 6:56 pm, Bharath <tiromarc...@[EMAIL PROTECTED]
> wrote:
> [...]
> class CBase
> {
> void dummy() {}
> };
>
> class CDerived: public CBase
> { };
>
> int main () {
> try {
> CBase * pba = new CDerived;
> CDerived * pd;
>
> pd = dynamic_cast<CDerived*>(pba);
> if (pd==0) cout << "Null pointer on first type-cast" << endl;
> } catch (exception& e) {cout << "Exception: " << e.what();}
> return 0;
> }
( presumably, the problem was that the "Null pointer on first type-
cast" message was being printed unexpectedly )
RTTI is a mechanism sup****ting cl***** employing virtual dispatch.
Just make a member of CBase virtual (even dummy() will do), and the
dynamic_cast<> will start working.
Cheers, Tony
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]