as I am quite new to C++ and still have to learn a lot, please bear with me and maybe some stupid questions:
Basically, I am declaring a map<wstring, int*>
, as most of the variables I am going to dereference and use are int
s (4 bytes). Unfortunately, there are rare ones being double
s (8 bytes) or short
s (2 bytes) and I don't have any influence on this. For the sake of simplicity and as I want to learn something I'd like to read all of the pointers into the same map. Here are my thoughts:
map[wstring] = (int*) short*;//or double*
Would the above work in terms of that only the beginning of the short's or double's memory address is stored in the map and not the memory's actual content?
As I know, which keys are different I would cast the pointers back to their type before dereferencing:
short = *((short*) map[wstring]); // or double = *((double*) map[wstring]);
From my point of limited knowledge this may work. I'd say that, although from the stored memory address there would normally be read 4 bytes, as this is what the map was declared for, now, by casting to short* or double*, I am saying that I'd like to read 2 or 8 bytes from the beginning of the stored address. In fact, it did work at least with shorts but I am not sure if this was just coincidence and I need to be sure.
Again, I am sorry if this is total nonsense and thanks in advance for mind enhancing answers.