`
mmdev
  • 浏览: 12920836 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

四种类型转换 cast

 
阅读更多

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);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics