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

前端 未结 3 540
梦如初夏
梦如初夏 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:58

    Containers store objects. References are not objects.

    The C++11 specification clearly states (§23.2.1[container.requirements.general]/1):

    Containers are objects that store other objects.

提交回复
热议问题