Jim West <jw***@jwest.ecen.okstate.edu> wrote in message news:<sl******************@emag.ecen.okstate.edu>. ..
Both
int a;
std::complex<float> b;
std::complex<float> c = static_cast<float>(a)*b;
and
int a;
std::complex<float> b;
std::complex<float> c = float(a)*b;
compile to exactly the same assembler on two different compilers.
However, I always seem to miss the subtleties of the language. Is
one version to be preferred over the other? I tend to use the latter
since it is more compact, which based on my track record is probably
the wrong way to go. :)
Stylistic suggestions greatly appreciated.
If I recall correctly using the c-style cast instead of the c++ style
cast can
allow for a reinterpret_cast<TYPETARGET>(TYPESOURCE) to occur when the
correct
conversion operators or constructors are unavailable. For built-in
types this may not be true.
However, your code snippet seems to indicate using C++ conversion
features and therefore your codes intent might be to require explicit
conversion rather than compiler defaulted conversion. If instead of
"int a" it was "MyClass a" the static_cast would be more specific
that you were expecting a conversion operation and not a bitwise
interpretation of the "a" bits.