-3

is there any reason for using static_cast on non pointer POD data types, like int, float, double?

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

Is there any reason/advantage on using that, I saw several answers that covers pointers, but plain POD data I could not find explicit answers about non-pointers.

Lefsler
  • 1,738
  • 6
  • 26
  • 46

1 Answers1

1

The best reason I've heard is because you can grep for static_cast and know you will only find casts whereas (int) is much less specific about what's going on in that expression.

Also, C-style casts can remove or add const or volatile and change types without any warnings. If you try to static_cast a const pointer/reference type to a non-const pointer/reference type, you will get a compile error.

Khouri Giordano
  • 796
  • 3
  • 9