Re: Pointer casting related question



On Mon, 7 Aug 2017 15:04:48 +0100
Daniel Boles <dboles src gmail com> wrote:
On 7 August 2017 at 14:59, Chris Vine <vine35792468 gmail com> wrote:

A static cast will carry out pointer adjustment when traversing an
inheritance graph to account for multiple inheritance or a vtable.
It is reinterpret cast which will not.
 

Indeed, thanks. I was only half-thinking at the time, and decided to
err on the side of caution. :)

I am one of the seemingly unpopular people who think it's perfectly
fine to static_cast if you know the conversion will always be valid -
i.e. so long as the program is not already in the process of crashing
or failing asserts, which obviously should not be treated as
reachable in released builds.

I agree with you.  I rarely use dynamic_cast (and I rarely use virtual
inheritance - mainly only for type erasure).  In practice you usually
know statically what your object consists of.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]