Possible implementation of std::addressof

79 Views Asked by At

This could be a duplicate[link] but, the answer is rather short and not very clear. In a possible implementation like this:

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

why is the const_cast needed?

0

There are 0 best solutions below