comp.lang.ada
 help / color / mirror / Atom feed
From: fjh@cs.mu.oz.au (Fergus Henderson)
Subject: Re: run-time type identification
Date: 1998/09/03
Date: 1998-09-03T00:00:00+00:00	[thread overview]
Message-ID: <6sm6p9$h9n$1@mulga.cs.mu.OZ.AU> (raw)
In-Reply-To: 01bdd73c$082f0230$f330ea9e@ukp03332

"Bob Fletcher" <bob@radge.globalnet.co.uk> writes:

>Yeah, this is the problem, there's no way of ensuring the safety of the
>operation.

What's wrong with trying the operation, and catching the exception
if it fails?

>The C++ dynamic_cast operator returns a zero (null) pointer if the
>object being pointed to is not of the correct class.

That's only half the story.  In C++, if you use `dynamic_cast' to
cast to a pointer type, it will return a null pointer if the
cast fails.  But if you use `dynamic_cast' to cast to a reference
type, it will throw an exception (of type `std::bad_cast') if
the cast fails.

--
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.




  reply	other threads:[~1998-09-03  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-03  0:00 run-time type identification Bob Fletcher
1998-09-03  0:00 ` Samuel Tardieu
1998-09-03  0:00   ` Bob Fletcher
1998-09-03  0:00     ` Fergus Henderson [this message]
1998-09-03  0:00     ` Matthew Heaney
1998-09-06  0:00       ` Samuel Tardieu
1998-09-03  0:00 ` Tucker Taft
1998-09-03  0:00 ` Steve Sabljak
1998-09-03  0:00   ` Matthew Heaney
1998-09-03  0:00   ` Steve Sabljak
1998-09-03  0:00 ` Matthew Heaney
1998-09-03  0:00   ` Bob Fletcher
1998-09-03  0:00     ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox