可能重复:
When should static_cast, dynamic_cast and reinterpret_cast be used?static_cast和reinterpret_cast有什么区别?
我使用c函数在C++中,其中在C的空隙型参数传递的结构被直接存储在相同的结构类型。
例如,在C.
void getdata(void *data){
Testitem *ti=data;//Testitem is of struct type.
}
做同样的在C++中,我使用的static_cast:
void foo::getdata(void *data){
Testitem *ti = static_cast<Testitem*>(data);
}
,当我使用reinterpret_cast
它做同样的工作,铸造结构
当我使用Testitem *it=(Testitem *)data;
这也做同样的事情。 但是结构如何受到它们三个的影响。
该线程说什么时候使用它。当我使用这三件事时,我在问这个结构有什么不同,我也忘了dynamic_cast。简单地说,我想知道结构是如何受到影响的。 – HariHaraSudhan
结构不受影响(除非在数字类型之间进行转换)。 –