Which C++ cast is closest to the C style (t) e one? I vaguely remember the C++ D&E saying t'is static_cast but I can't remember and don't have the book here with me.
Printable View
Which C++ cast is closest to the C style (t) e one? I vaguely remember the C++ D&E saying t'is static_cast but I can't remember and don't have the book here with me.
Yes, I'd say static_cast is closest, since it can be used in several different situations.
I thought it was reinterpret_cast
http://publib.boulder.ibm.com/infoce...rpret_cast.htm
Hmm ok thanks guys.
Code:#include <iostream>
int main()
{
float f = 10.0f;
int i1 = (int) f;
int i2 = static_cast<int>(f);
int i3 = reinterpret_cast<int>(f); // error cannot convert float to int
std::cout << i1 << '\n';
std::cout << i2 << '\n';
std::cout << i3 << '\n';
}
\:)/