Saturday, August 13, 2016

C++ What does static_cast can do?

The behavior of static cast is well described in many sources. Below is the code example that could reveal some usage cases.
The output of the program execution is the next:

static_cast<int>(1.0) = 1
static_cast<int>(0xFFFFFFFFU) = -1
static_cast<int>(0xFF11FFFFFFULL) = 0x11FFFFFF
static_cast<float>(5) = 5.000000
static_cast<unsigned int>(-1) = 4294967295
(d1.*d1_func_ptr)() returns 1
(d12.*d12_func_ptr)() returns 2
(d12.*d12_func_ptr)() returns 1
(d1.*d1_func_ptr)() returns 2 

No comments:

Post a Comment