What's the standard idiom for general casting in C++ these days?
The C idiom is:
(int)t.
I've been using:
static_cast<int>(t).
But I'm most comfortable with:
int(t).
What do the gurus do?
What's the standard idiom for general casting in C++ these days?
The C idiom is:
(int)t.
I've been using:
static_cast<int>(t).
But I'm most comfortable with:
int(t).
What do the gurus do?
C++ style cast is always preferable. I could cite three good reasons for preferring C++ casts over C-style cast:-
1) They helps in readability. Anyone with one glance at your code get to know that cast is used whereas it's not the case with C-style casts.
2) There are 4 different casts in C++ which clearly express the intent of the programmer.
3) C++ style cast are checked by compiler to make sure whether casting is used in the proper context OR not.