In some cases, you will have to convert between types. For example, this may be because the data is provided in a different type to the routines that you use to process it. You may have a library that processes floating point numbers as float, but your data is inputted as double. You are aware that the conversion will lose precision but know that this will have little effect on the final result so you do not want the compiler warning you. What you want to do is tell the compiler that the coercion of one type to another is acceptable.
The following table summarizes the various cast operations you can use in C++11:
Name | Syntax |
Construction | {} |
Remove const requirement | const_cast |
Cast with no runtime checks | static_cast |
Bitwise ... |