Are pointers allowed as keys in ordered STL containers?

后端 未结 4 870
遥遥无期
遥遥无期 2020-12-19 06:33

There\'s this other question asking about how comparing pointers is supposed to be interpreted wrt the C++ Std.

So I was wondering what the C++ Std has to say about

4条回答
  •  自闭症患者
    2020-12-19 07:17

    "They may valid but don't" is the answer I would give.

    Obviously there is the issue of comparability that you raise, but the reason you don't want to is because of the lack of reference management on "vanilla" pointers. It's very easy for the object to be deleted without it being removed from the container, resulting in an invalid pointer and an access violation next time you go to access it.

提交回复
热议问题