How to fill an array of unique_ptr?

前端 未结 3 581
眼角桃花
眼角桃花 2020-12-31 22:21

Is it possible to use std:fill to fill an array of unique_ptrs? The intention is to have distinct pointers to distinct objects which are initialize

3条回答
  •  渐次进展
    2020-12-31 23:01

    Another solution:

    std::unique_ptr ar[3];
    
    size_t i;
    for (i = 0; i < elementsof(ar); ++i) {
        ar[i].reset(new int);
    }
    

提交回复
热议问题