Advertisement
tinyevil

Untitled

Aug 5th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. Lets say operator[] returns a pointer.
  2. For a const map it returns a nullptr.
  3. Seems good so far?
  4. But we want *map[10] = "Hello" to work.
  5. So for non-const map, map[10] must return
  6. a valid pointer even if key 10 doesnt exist
  7. yet.
  8. But this means the semantics of [] depends
  9. on the const-ness of the map: it creates
  10. a key if the map is non-const and does not
  11. if its const. Even if we don't use the result
  12. of [] for an assignment:
  13.  
  14. if ( *map[10] == "ten" ){ // creates key 10
  15. // or not?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement