Does C++11 allow vector?

前端 未结 4 782
不思量自难忘°
不思量自难忘° 2020-11-22 11:32

Container requirements have changed from C++03 to C++11. While C++03 had blanket requirements (e.g. copy constructibility and assignability for vector), C++11 defines fine-g

4条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 11:56

    Complementing the other answers, another approach is to use:

    vector> vec;
    

    If it is the case where you want to enforce that only vec has ownership of its items. Or if you want a dynamic of moving items into vec and at some point move them out.

    As pointed out, pointer const semantics may be confusing, but shared_ptr and unique_ptr aren't. const unique_ptr is a const pointer and unique_ptr is a const pointee as you would expect.

提交回复
热议问题