c++templatesmember-pointers

Offset of pointer to member


template<class T, typename U> ptrdiff_t foo(T U::* m)
{
    // return offset
}

How I can get the offset of the field 'm' in this context? I would prefer to use am compile-time expression.

Thanks in advance for any help. Best regards


Solution

  • Sounds like you're looking for the offsetof() macro.