Hi all,
I'm trying to use a map of string* and unsigned ints but results are
not good. I've used as example this piece of code:
http://www.sgi.com/tech/stl/Map.html
And I have done this:
#include <iostream>
#include <map>
using namespace std;
struct ltstr {
bool operator()(const string * s1, const string * s2) const {
return *s1 == *s2;
}
};
int main() {
map<const string *, unsigned int, ltstr> m;
const string * s1 = new string("Hello");
const string * s2 = new string("Buh");
m[s1] = 3;
m[s2] = 4;
const string * s4 = new string("Hello");
cout << "S4 VALUE: " << m[s4] << "\n";
delete s1;
delete s2;
delete s4;
return 0;
}
For some reason I get:
$ ./maptest
S4 VALUE: 0
Can't understand what's happening. I was expecting value 3. Shouldn't
*s1 == *s2 return true iff s1 and s2 are lexicographically equal?
Cheers,
Paulo Matos