C++ inserting unique_ptr in map

前端 未结 3 879
醉梦人生
醉梦人生 2020-12-01 12:00

I have a C++ object of type ObjectArray

typedef map> ObjectArray;

What is the syn

3条回答
  •  日久生厌
    2020-12-01 12:08

    If you want to add an existing pointer to insert into the map, you will have to use std::move.

    For example:

    std::unique_ptr classPtr(new Class1);
    
    myMap.insert(std::make_pair(0,std::move(classPtr)));
    

提交回复
热议问题