可能实现std :: addressof

时间:2017-05-24 12:13:29

标签: c++ c++11 const-cast addressof

这可能是重复的[link],但答案很短,不太清楚。在这样的可能实现中:

template <class T>
T * addressof(T & v)
{
  return reinterpret_cast<T *>(& const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}

为什么需要const_cast

0 个答案:

没有答案