c++ - Use static_cast on non-pointer POD instead of c style cast -


this question has answer here:

is there reason using static_cast on non pointer pod data types, int, float, double?

float v = 100; int x = (int) v vs int x = static_cast<int>v 

is there reason/advantage on using that, saw several answers covers pointers, plain pod data not find explicit answers non-pointers.

the best reason i've heard because can grep static_cast , know find casts whereas (int) less specific what's going on in expression.

also, c-style casts can remove or add const or volatile , change types without warnings. if try static_cast const pointer/reference type non-const pointer/reference type, compile error.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -