I'm sorry, but I've looked for this everywhere. In my book they start using this and don't say what it is. I've looked on the internet, but it still is unclear to me exactly what static_cast does. Can anyone help?
A static cast just acts as a temporary conversion from one type to another.
For example:
1 2 3 4 5 6 7 8 9
int main() {
int a = 97; // The decimal equivalent of 'a'
cout << static_cast<char>(a) << endl; // "Cast" the 97 as it's char counterpart
return 0;
}
Output:
a
This is for the VC++ compiler but their static_cast is standard compliant as far as I can tell (meaning this should work on any compiler you use). Please note that it's not just a temporary conversion from one type to another.