static_cast,dynamic_cast,reinterpret_cast和const_cast的区别详解
#include
using namespace std;
class Base
{
public:
int _base;
virtual void printinfo()
{
cout << _base << endl;
}
};
class Derived : public Base
{
public:
int _derived;
virtual void printinfo()
{
cout << _derived << endl;
}
};
int main(void)
{
Base b1;
Derived d1;
int aInt = 10;
long aLong = 11;
float aFloat = 11.11f;
double aDouble = 12.12;
Derived* pd = static_cast
Base* pb = static_cast
Derived& d = static_cast
Base& b = static_cast
aInt = static_cast
void* sth = static_cast
double* bDouble = static_cast
cout << *bDouble << endl;
Base* pb1 = dynamic_cast
//Derived* pd1 = dynamic_cast
int bInt = reinterpret_cast
cout << bInt << endl;
pb1 = reinterpret_cast
int* cInt = reinterpret_cast
cout << (int)*cInt << endl;
const Base* bBase = new Base();
Base* cBase = const_cast
//Base* dBase = dynamic_cast
//Base* eBase = static_cast
//Base* fBase = reinterpret_cast
return 0;
}
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播