Deallocating objects stored in a vector?

前端 未结 7 477
一生所求
一生所求 2020-12-10 06:17

I have a class that creates a vector of objects. In the deconstructor for this class I\'m trying to deallocate the memory assigned to the objects. I\'m trying to do this by

7条回答
  •  無奈伤痛
    2020-12-10 06:40

    for(std::vector::iterator beg = myVector->begin(), end = myVector->end(); beg != end; beg++)
    {
        delete *beg;
    }
    myVector->clear();
    

提交回复
热议问题