This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: map::find


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]