|
|
On Mon, 09 Mar 2009 00:33:32 +0100, Nicolas Alvarez
<nic### [at] gmailcom> wrote:
>
> void foo(Alpha* ptr) {
> Beta* beta = dynamic_cast<Beta*>(ptr);
> }
>
> If ptr is a Beta object that was (maybe implicitly) cast to a Alpha*,
> then
> beta is now equal to ptr (except its type is Beta*, so you can use Beta
> members). If ptr actually pointed to an Alpha, or a Delta (another
> subclass
> of Alpha), then the cast will throw a std::bad_cast exception.
No. A failed dynamic_cast of a pointer simply returns a null pointer. Only
failed casts of a reference result in a std::bad_cast exception.
--
FE
Post a reply to this message
|
|