This isn't C, this is C++. A C equivalent would have been
(float)nValue1
You are correct in that (in C++),
float(nValue1)
,
(float)nValue1
, and
static_cast<float>(nValue1)
are the same.
When you use a C-style cast (or a function-style cast that you used, which is the same thing) in a C++ program, you're asking the compiler to try all of the following, in this order, and use the first one that can be compiled:
1. const_cast
2. static_cast (with some extensions, irrelevant here)
3. static_cast (with extensions) followed by const_cast
4. reinterpret_cast
5. reinterpret_cast followed by const_cast
the biggest problem is if you're casting between pointers and the compiler picks reinterpret_cast where you intended a static_cast. Also, C++ programs are usually trying to be const-correct and any surprise const_cast is unwelcome as well.