On Fri, 29 Aug 2003 14:37:01 -0400, Suzanne Vogel <suzanne_e_vogel@hotmail.com> wrote:
[color=blue]
>** Isn't the 'static_cast' operator the same as traditional type
>casting? ie, Aren't the following ways of getting b1, b2 the same?
>
>// 'Derived' is derived from 'Base'
>Derived* d = new Derived();
>Base* b1 = static_cast<Base*>(d);
>Base* b2 = (Base*)d; // traditional type casting[/color]
In this particular case the two give equivalent effect.
Generally the C-style cast will employ whatever combination of
static_cast, const_cast and reinterpret_cast necessary to achieve
the specified type conversion.
Often the programmer does not understand _what_ the effect is,
so to the degree casting is unavoidable: at least avoid the C-style
cast, which is only there for backward compatibility.
[color=blue]
>Such is my understanding from code samples, my own uses, and this:
>
http://www.cplusplus.com/doc/tutorial/tut5-4.html[/color]
Nope. I don't think tutorial is a particularly bad one, but it was
written in a time when code had to be "compromised" to accomodate
the then current compilers. So, for example,
#include <iostream.h>
in that tutorial (even on the page you referred to) is non-standard.
I wish the author could have pointed that out, not give the impression
that this was a tutorial about standard C++.