Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lets say operator[] returns a pointer.
- For a const map it returns a nullptr.
- Seems good so far?
- But we want *map[10] = "Hello" to work.
- So for non-const map, map[10] must return
- a valid pointer even if key 10 doesnt exist
- yet.
- But this means the semantics of [] depends
- on the const-ness of the map: it creates
- a key if the map is non-const and does not
- if its const. Even if we don't use the result
- of [] for an assignment:
- if ( *map[10] == "ten" ){ // creates key 10
- // or not?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement