reinterpret_cast作用为:
允许将任何指针转换为任何其他指针类型。 也允许将任何整数类型转换为任何指针类型以及反向转换。
语法还是老样子:
reinterpret_cast < type-id > ( expression )
滥用 reinterpret_cast 运算符可能很容易带来风险。 除非所需转换本身是低级别的,否则应使用其他强制转换运算符之一。
reinterpret_cast 运算符可用于 char* 到 int* 或 One_class* 到 Unrelated_class* 之类的转换,这本身并不安全。
reinterpret_cast 的结果不能安全地用于除强制转换回其原始类型以外的任何用途。 在最好的情况下,其他用途也是不可移植的。
reinterpret_cast 运算符不能丢掉 const、volatile 或 __unaligned 特性。
例如将 shared_ptr * b 转换成 int** a
int** a = reinterpret_cast<int**>(b);
std::vector<std::shared_ptr<int> > param;
param.push_back(std::make_shared<int>(5));
param.push_back(std::make_shared<int>(5));
std::shared_ptr<int>* b = param.data();
int** a = reinterpret_cast<int**>(b);