Why does storing references (not pointers) in containers in C++ not work?

前端 未结 3 551
梦如初夏
梦如初夏 2020-11-29 06:43

In my program I have a STL set.

set myStrings;

To improve the efficiency of my code I changed it to hold, only pointers. (I d

3条回答
  •  悲哀的现实
    2020-11-29 06:52

    Not directly relevant to the "why", but to give an answer to the implied desire to do this, I would mention that the c++11 standard library has std::reference_wrapper to enable this. It is implicitly convertible to a reference and it is storable in standard containers.

提交回复
热议问题