"cpp_weenie" <cp*@weenie.com> wrote in message news:<vo************@news.supernews.com>...
reinterpret_cast<int>(dmp)
Here, dmp is of type int Derived::*.
I have verified that sizeof(dmp) and sizeof(int) are the same.
The compiler balks with the following:
'reinterpret_cast' : cannot convert from 'int Derived::* ' to 'int'
There is no context in which this conversion is possible
Why would this happen?
The conversion isn't defined by C++; hence, you can't do that.
Shouldn't a reinterpret_cast always succeed as long as the types involved
are the same size?
Yes and no; because there's no predefined conversion, reinterpret_cast
wouldn't know what to do. If you think you know better, you can try
this:
int i = reinterpret_cast<int &>(dmp);
That is, C++ treats dmp as an int and copies it as it would an int.
The behavior of this code is undefined by ISO, although the
implementation may define it. As a result, it's not portable; I'd
recommend against it.
Perhaps you can make do with offsetof in <cstddef> instead?
- Shane