By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,838 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,838 IT Pros & Developers. It's quick & easy.

map & find()

P: n/a
Hello
i created map<myclass1*,myclass2*> object.
I have problem with find function. It only works when
myclass1* is string or int (it does not work for char* and myclass1*).
Is it normal or i have made mistake somewhere ?
How does find() compares objects ? Maybe i should have written some
compare() function ?

Thanx
Michal
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"vertigo" <ax***@wp.pl> wrote in message
news:ci**********@nemesis.news.tpi.pl...
Hello
i created map<myclass1*,myclass2*> object.
I have problem with find function. It only works when
myclass1* is string or int (it does not work for char* and myclass1*).
Is it normal or i have made mistake somewhere ?
How does find() compares objects ?
If the objects are pointers then it compares pointers, which is almost never
what you want to do.
Maybe i should have written some
compare() function ?


Yes or a comparison functor, either can work.

struct Comp
{
bool operator()(const myclass1* x, myclass1* y) const
{
// return true if x is less than y
}
};

map<myclass1*,myclass2*,Comp> my_map;

john
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.