1.static_cast<type>(expression)
for example:
c style
int i = (int)2.0;
c++ style
double d = 1.0
int i = static_cast<int>(d);
2.const_cast<type>(expression) 常常用于转化非常量到非常量
#include <cstdlib>
#include <stdexcept>
#include <iostream>
using namespace std;
int f(int & i) throw (runtime_error) {
}
/*
*
*/
int main(int argc, char** argv) {
const int i = 5;
f(const_cast<int &>(i));
return 0;
}
3.dynamic_cast<type>();
4.reinterpret_cast<type>();