在 提高::详细:: addressof_impl :: F() 一系列 reinterpret_cast
s完成以获取对象的实际地址以防万一 class T
已超载 operator&()
:
template<class T> struct addressof_impl
{
static inline T* f( T& v, long )
{
return reinterpret_cast<T*>(
&const_cast<char&>(reinterpret_cast<const volatile char&>(v)));
}
}
投射的目的是什么? const volatile char&
而不只是铸造 char&
?
直接演员 char&
会失败的 T
具有 const
要么 volatile
资格赛 - reinterpret_cast
不能删除这些(但可以添加它们),和 const_cast
无法进行任意类型更改。
对象可能是 const
要么 volatile
或者两者兼而有之(如同可能的那样),在这种情况下,它可能是非法的 reinterpret_cast
它属于缺乏这些属性的类型。 (走向相反的方向当然不是问题)。
直接演员 char&
会失败的 T
具有 const
要么 volatile
资格赛 - reinterpret_cast
不能删除这些(但可以添加它们),和 const_cast
无法进行任意类型更改。
对象可能是 const
要么 volatile
或者两者兼而有之(如同可能的那样),在这种情况下,它可能是非法的 reinterpret_cast
它属于缺乏这些属性的类型。 (走向相反的方向当然不是问题)。