What is "o" in this example? Because if it's not an int, then why would you use the "pointer to an int" typecast? (Line 1)
Also, by converting your pointer to an int, 'pointer' will not be a hex value, every digit will be 0-9. Print it out to the console if you want but I'm almost certain that by casting it out of a "pointer to a" type, that the A-F values will be lost.
Essentially, what's happening is:
o is a pointer to an object. The value is (for example) 0x20 (of course in reality, you would never get such a low number)
pointer is declared as an int, but we are not ready to assign its value just yet because we have to do some casting first , in the order of right to left
a temporary pointer is created, it has the same value as pointer (0x20) but this pointer instead declares that the target memory contains an int, not an object.
a temporary int is created, it has the value value 0x20 which has a binary representation of 00100000, which is 32.
pointer is initialised to this temporary int value: 32
because you are putting the int into the stringstream, and not the pointer, "32" will be added to the string stream, not "20"
Object *ObjectPointer = &o; //If o is an object, do this one, otherwise do the one below
Object *ObjectPointer = o; //If o is a pointer to an object, do this one, otherwise do the one above
std::string hex;
stringstream ss;
ss << hex << ObjectPointer;
should keep it in hex... Either that or I've gone a bit cuckoo...