Hi, I'm trying to keep MFC out of this project and so I'm using the
stl std::map on the heap. I was originally using a char * as the key,
but I ran into the "duh, obvious -- it's comparing pointers" issue,
and switched to the CString (<atlstr.h> version, NOT the CLR version)
use. I thought this would solve the pointer issue since the operators
for CString are overridden.
Now, I declare the map as:
std::map<CString, byte*>* g_VarMap; //byte is typdef'd unsigned
char. also on the heap.
Now, I add strings to the map and this works entirely as expected.
However, later on, I try to do a find() to grab the value. Now,
digging into the guts, the find() is doing an == to detect if the
objects are the same. CString has overrided this operator so that it
compares the guts of the strings, not the pointers.
I still get find failing. Here's an example of a little dummy test.
Now, as you can see here, my map has the strings in it and pointers to
memory locations.
- g_VarMap [5](("AA",0x003a9e0b ""),("BB",0x003a9e1b ""),("XX",
0x003a9c95 ""),("YAR",0x003a9c96 ""),("YY",0x003a9c94 ""))
find returned (<Bad Ptr>,0xcdcdcdcd <Bad Ptr>)
when I do a find on YAR.
The code is a bit long to put here, but I'm sure this is something you
know the answer to.
Any ideas? To me, the == operator should return that there is a
match.