This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: map::find
- From: caj at cs dot york dot ac dot uk
- To: "Maxim Vetrov" <muxas at mail dot ru>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Mon, 31 Oct 2005 10:54:25 -0000 (GMT)
- Subject: Re: map::find
- References: <43667F7A.2090105@mail.ru>
First of all, I'll just say this a mailing list about developing
libstdc++, not using it.
Your problem is that the map only stores the pointers it is given, not the
string that they point at. You in seperate places a) aren't careful to
make sure that those strings don't get deallocated, and in other places
you change the string. My short advice would be:
Don't use raw pointers unless you have to, and if you have to use raw
pointers (and I can't see any reason you are using char*s instead of
std::strings), it's your job to make sure you look after the things they
point at the whole time they are in the map, don't change them, don't let
them go out of scope.
Not being insulting, go and get a good book in C++ (I like Bjorne's "C++
programming language), and try to avoid use of pointers except when you
have no other choice :)
Chris