Evo. G Tech Team Forum
Welcome to Evo. G Tech Team Forum. We have moved to a new website : www.evogtechteam.com

Thanks you.

by Evo. G Tech Team Management.

Join the forum, it's quick and easy

Evo. G Tech Team Forum
Welcome to Evo. G Tech Team Forum. We have moved to a new website : www.evogtechteam.com

Thanks you.

by Evo. G Tech Team Management.
Evo. G Tech Team Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

四种强制类型转换之一reinterpret_cast

Go down

四种强制类型转换之一reinterpret_cast Empty 四种强制类型转换之一reinterpret_cast

Post by too wei June 23rd 2015, 13:59

reinterpret_cast
-这种转换能够把不可能的转换变成可能
-执行低级转型,结果取决于编译器(不可移植),低级代码以外很少见
-操作结果只是简单的从一个指针到别的指针的值的二进制拷贝。在类型之间指向的内容不做任何类型的检查和转换。
-这种转换可能会使值变成不确定


struct T
{
int data;
double point;
};
int main()
{
int value = 5555555;


T * mm = reinterpret_cast(&value); //把int转换成结构
printf("%d , %d \n",mm->data,mm->point);


int *back = reinterpret_cast(&mm); //再从结构转换回int
printf("%d\n",*back);


*back = 55; //重新赋值
printf("%d\n",*back);
return 0;

}

too wei
Sponsor
Sponsor

Posts : 31
Points : 66331
Reputation : 0
Join date : 2015-04-21
Age : 25
Location : Johor

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum