Hy,
I do not understand the output of the following piece of program.
Why does o1, o2, o3 give always 1.
I would except a memory offset internal of the struct Edge.
Maybe there is something wrong with the output formating?
I would be grateful for any hint
thank you very much
dziadgba
o1, o2, and o3 are pointers to members. ostream does not have an overload that handles pointers to members,
so the compiler is finding a conversion from pointer-to-member to something that ostream can handle. The
only such conversion is to bool. A non-NULL pointer is always true (1).
Many programmers would simply cast the pointer to, say, a void* and output that, however
the standard makes no guarantee that sizeof a pointer-to-member be equal to sizeof ( void* )
(and indeed likely it is not).
Good bet? Take the address of o1, reinterpret_cast the address to an unsigned char*, then
output sizeof( o1 ) bytes in hex beginning at that address (though you will need to account for
machine endianness).