Convert pointer to data member to void *
c++, casting, pointer-to-member, type-conversion
Solution
A pointer to non-static class member type is not the same as a object pointer type; they behave very differently. In fact, you cannot even dereference a pointer to member with `*`. To access a member through a pointer to member, you use the `.*` and `->*` operators instead. If you could cast it to an object pointer type like this, what would happen, then, if you dereferenced it with `*`?
Only object pointer types have a standard conversion to `void*` (§4.10):
A prvalue of type "pointer to cv `T`," where `T` is an object type, can be converted to a prvalue of type "pointer to cv `void`".
They're so different that the standard even goes out of its way to make sure that the term "pointer" doesn't include pointers to non-static members (§3.9.2):
Except for pointers to static members, text referring to "pointers" does not apply to pointers to members.
Problem
I know that I can get a pointer to data member for a class or struct but the last line of the following code fails to compile: ``` struct abc { int a; int b; char c; }; int main() { char abc::*ptt1 = &abc::c; void *another_ptr = (void*)ptt1; } ``` Why can't I convert ptt1 to another_ptr? We're talking about pointers so one pointer should have a similar dimension to another one (although conceptually different)?