K
Kobe
Hi,
if I need to convert a size_t to an int, in "older" C++ I'd write the
following code (using C-like "casting"):
<CODE>
std::vector<...> v;
int count = (int) v.size();
// v.size() returns size_t
</CODE>
Now that modern C++ has different cast tools, how the above code should
be changed? Should I use static_cast or reinterpret_cast ?
e.g.
int count = static_cast<int>(v.size());
Moreover, sometimes I need to convert 32 bits unsigned ints (typedef
unsigned int DWORD) into pointers.
e.g.
<CODE>
// Old style C casting
DWORD address;
// address = ...
AClass * myObject = (AClass *)address;
</CODE>
Should I use static_cast or reinterpret_cast in this case?
Thanks in advance,
K
if I need to convert a size_t to an int, in "older" C++ I'd write the
following code (using C-like "casting"):
<CODE>
std::vector<...> v;
int count = (int) v.size();
// v.size() returns size_t
</CODE>
Now that modern C++ has different cast tools, how the above code should
be changed? Should I use static_cast or reinterpret_cast ?
e.g.
int count = static_cast<int>(v.size());
Moreover, sometimes I need to convert 32 bits unsigned ints (typedef
unsigned int DWORD) into pointers.
e.g.
<CODE>
// Old style C casting
DWORD address;
// address = ...
AClass * myObject = (AClass *)address;
</CODE>
Should I use static_cast or reinterpret_cast in this case?
Thanks in advance,
K