Destructor is called when I push_back to the vector

前端 未结 4 577
青春惊慌失措
青春惊慌失措 2020-12-19 18:38

I have this class definition:

class FlashStream
{
public:
    explicit FlashStream(const char * url, vector * headers, vector * dat         


        
4条回答
  •  无人及你
    2020-12-19 18:53

    Putting copies of objects in vector/map etc. are bad idea. The destructor called when the temporary objects get destroyed. The destructor for the objects will be again called whenever the Vector/Map resizes or rearranges.

    To avoid those you should store pointer to those objects. You may like to use shared_ptrs here.

提交回复
热议问题