Using operator[] on empty std::vector

前端 未结 7 922
迷失自我
迷失自我 2021-01-12 05:29

I was advised a while ago that is was common place to use std::vector as exception safe dynamic array in c++ rather than allocating raw arrays... for exampl

7条回答
  •  一生所求
    2021-01-12 06:18

    Could you use iterators instead of pointers?

    {
        std::vector scoped_array (size);
        std::vector::iterator pointer = scoped_array.begin();
    
        //do work
    
    } // exception safe deallocation
    

提交回复
热议问题