Can I use const in vectors to allow adding elements, but not modifications to the already added?

后端 未结 14 600
既然无缘
既然无缘 2020-12-01 04:54

My comments on this answer got me thinking about the issues of constness and sorting. I played around a bit and reduced my issues to the fact that this code:



        
14条回答
  •  执笔经年
    2020-12-01 05:38

    I'm with Noah: wrap the vector with a class that exposes only what you want to allow.

    If you don't need to dynamically add objects to the vector, consider std::tr1::array.

提交回复
热议问题