使用reinterpret_cast在不相关的指针类型之间进行投射。
使用static_cast进行显式支持的转换。
使用dynamic_cast将一种类型的指针转换为派生类型的指针。
如果您知道指向父类型的指针指向子类型,则可以安全地将父类型的static_cast安全地指向子类型。从子类型指针到父类型指针的转换是隐式的,不需要显式转换。
一个从我自己的代码库的reinterpret_cast例如:
unsigned int CTaskManager::CWorker::WorkerMain(void* Parameters)
{
CWorker* This = reinterpret_cast<CWorker*>(Parameters);
// ...
}
bool CTaskManager::CWorker::Initialize()
{
// ...
// Create worker.
m_ThreadHandle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &(WorkerMain), this, 0, NULL));
// ...
}
重复的[?为什么我们在C++的reinterpret_cast当两分链式的static_cast可以做的工作(http://stackoverflow.com/questions/ 5025843 /为什么-DO-我们具备的,重新诠释 - 现浇C-当两链静态铸造灿-DO-其-J)。基本答案是:因为其他演员表达式无法完成的事情。 – 2011-03-04 04:39:55
请参阅本主题:[为什么当两个链接的static_cast可以完成它的工作时,我们在C++中使用reinterpret_cast](http://stackoverflow.com/questions/5025843/why-do-we-have-reinterpret-cast-in- c-when-two-chained-static-cast-can-do-its-j) – Nawaz 2011-03-04 04:40:14
@James::D .... – Nawaz 2011-03-04 04:40:48