1.static_cast??
2.dynamic_cast
3.const_cast
4. reinterpret_cast
例子1:
float x;
cout<<static_cast<int>(x);
...
f(static_cast<string>("hello"));
例子2:
class Car;
class? Cabriolet:pbulic Car
{
};
class Limousine:public Car
{
};
void f(Car *cp)
{
??? Cabriolet *p = dynamic_cast <Cabriolet*>(cp);
??? if ( NULL != p)
? ? {
??? }
}
例子3:
const? char *pChar1 = "Hello,microsoft visual studio? will help you ",
char * pChar2 = const_cast<char*>(pChar1);
例子4:
void * pT;
unsigned long? address= reinterpret_cast<unsigned long>(pT);