C++ std::queue::pop() calls destructor. What of pointer types?

前端 未结 3 651
滥情空心
滥情空心 2020-12-28 17:49

I have a std::queue that is wrapped as a templated class to make a thread-safe queue. I have two versions of this class: one that stores value types, one that s

3条回答
  •  佛祖请我去吃肉
    2020-12-28 18:08

    Online sources are worth what you pay for them - get a proper reference like Josuttis's book. pop() does not "call the destructor" - it simply removes an element from the queue adaptor's underlying representation (by default a std::deque) by calling pop_front() on it. If the thing being popped has a destructor, it will be used when the popped object goes out of scope, but the queue class has nothing to do with it.

提交回复
热议问题