Why Can't I store references in a `std::map` in C++?

后端 未结 6 1144
执念已碎
执念已碎 2020-12-02 19:55

I understand that references are not pointers, but an alias to an object. However, I still don\'t understand what exactly this means to me as a programmer, i.e. what are re

6条回答
  •  -上瘾入骨i
    2020-12-02 20:32

    They way I understand it, references are implemented as pointers under the hood. The reason why you can't store them in a map is purely semantic; you have to initialize a reference when it's created and you can't change it afterward anymore. This doesn't mesh with the way a map works.

提交回复
热议问题