stl container of references C++11

前端 未结 4 714
感动是毒
感动是毒 2020-12-18 10:32

I know this question was asked a million of times. And most of answers just says that object should be CopyAssignable and CopyConstructible. But documentation clearly says t

4条回答
  •  一向
    一向 (楼主)
    2020-12-18 10:38

    The rules apply until C++11. In C++11 is required that element type is a complete type and meets the requirements of Erasable in which case references are not.

    However you can use std::reference_wrapper to wrap your references and store them in a vector.

    std::vector> vector_of_references;
    

提交回复
热议问题