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.
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.
Last edited by cboard_member; 05-05-2006 at 09:34 AM. Reason: t'was should've been t'is, dag nabbit!
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
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
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hmm ok thanks guys.
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
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'; }
\/
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry