Should I really use static_cast every single time I want to convert between primitive types?
- 阅读更多 关于 Should I really use static_cast every single time I want to convert between primitive types?
What makes this long l = 1; char c = static_cast<char>(l); float f = 1.0f; int i = static_cast<int>(f); better than this long l = 1; char c = (char)l; float f = 1.0f; int i = (int)f; when casting one primitive data type to another? I've got much of legacy code that uses the second style for type casting in similar situations, so this is also a question about should I or may I not perform full-scale revision of that code. R. Martinho Fernandes Future-proofing. Let's say in the future I do this: float blah = 1.0f; float* f = &blah; Now, int i = static_cast<int>(f); stops compiling, but int i =