Re: Replacing old C-style casts with static|reinterpret_cast?



On Wed, 10 May 2017 20:25:49 +0100
Daniel Boles <dboles src gmail com> wrote:
On 10 May 2017 at 20:24, Daniel Boles <dboles src gmail com> wrote:


Do you have any recommended reading on the cases which C casts can
handle, and adjust as required, but reinterpret_cast<> cannot? That
was surprising to me as I thought the C++ casts could cover all the
angles. 

Sorry, of course I meant 'reinterpret_cast<> and any other C++
casts', i.e. cases that only the old C cast can handle. Some examples
of discussion and a note of the relevant Standard bits (I have the
PDF open permanently but never have much luck searching!) would be
much appreciated.

I don't have any recommended reading I am afraid.  The ability to use C
casts to cast from derived to private base is required by these words
in ยง5.4/4 of C++14, in describing the behaviour of C casts:  "The same
semantic restrictions and behaviors apply, with the exception that in
performing a static_cast in the following situations the conversion is
valid even if the base class is inaccessible" .

Therefore, C casts can cast as if by static_cast to inaccessible types
even where static_cast cannot.

Chris


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