Skip to main content
gamedev.net
🔒 Locked

VERY quick question

Started by xSKOTTIEx 1 reply 800+ views
Original Post
xSKOTTIEx
xSKOTTIEx
in a std::map, if you try to access an item that isnt there, what does it return? i googled it and cant figure it out? map["non-existant item"]....?
---------Coming soon! Microcosm II.
BradDaBug
BradDaBug
Bad things. Don't do that. Use map::find intead. That'll return an iterator. If the iterator == map::end() then it didn't find it.

Edit: btw, that map::end() means yourmap.end(); it's not a static method or anything. Same for find().

Edit again: Ok, actually, if you do map["not existant item"] the map will actually insert the item into the map. But this may not necessarily be desirable, so use insert() and find() instead.
I like the DARK layout!
Hedos
Hedos
Yep, it'll create an item and associate it with this key. That's why you can't have item types without default constructors in a std::map.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.