Re: std::map
- From: "Ashish" <akohli_2004@xxxxxxxxxxx>
- Date: Thu, 18 Sep 2008 15:30:20 +0530
Thanks
std::string solves the problem so i dont need to use const char*
"Ashish" <akohli_2004@xxxxxxxxxxx> wrote in message
news:OUvQ6LLGJHA.2440@xxxxxxxxxxxxxxxxxxxxxxx
using std::string as key in map i dont need to overload any extra
functionality. map will be like
std::map<std::string, data>
But using const char* i need to add the functionality for key_compare and
allocator_type.
std::map<const char*,data,functionpointer,allocator> mapdata;
where functionpointer contains pointer to function which compare both keys
and allocator will allocate memory for key.
Because if i insert item in map like
mapdata.insert(std::make_pair("abc",data)); then
mapdata.find("abc") will return that item.
while if i insert item like
std::string str = "abc";
mapdata.insert(std::make_pair(str.c-str(),data)); then
mapdata.find("abc") will not return that item.
Since i cant save all keys in some class so i need to allocate memory for
each key in map itself.
Please suggest how to allocate memory for char* in map. If allocator_type
does this job then please give any sample how?
"Ashish" <akohli_2004@xxxxxxxxxxx> wrote in message
news:emAnpKJGJHA.1280@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for reply
Yes if i use std::map<std::string, data> then it solves the problem.
I wrote data was corrupt when i use std::map<const char*,data>
it means if i insert one item in map with index "abc" and now if i search
that item by using mapname.find("abc") then it doesn't return that item.
When i check memory of mapname then it doesn't contains "abc" it first
place.
Well std::string solved the problem. But ifi want to use const char* then
please what what i need to do? should i create a new class derived from
map and override some operators/functions?
.
- Follow-Ups:
- Re: std::map
- From: Tim Roberts
- Re: std::map
- References:
- std::map
- From: Ashish
- Re: std::map
- From: Igor Tandetnik
- Re: std::map
- From: Ashish
- Re: std::map
- From: Ashish
- std::map
- Prev by Date: About const_cast and volatileness
- Next by Date: Re: vtable issue
- Previous by thread: Re: std::map
- Next by thread: Re: std::map
- Index(es):
Relevant Pages
|