Two Pointers queue element is the same, remove the pointer element in a queue, another queue in how to deal with? The pointer is not become NULL last q2!
class A { Public: A (int A) { Id=a; } Int id=0; };
Void main () { DequeDequeA * A=new A (3); A * b=new A (4); Q1. The push_back (a); Q1. The push_back (b); Q2. The push_back (a); Q2. The push_back (b); For (auto & amp; P: q1) { delete p; P=NULL; } For (auto & amp; P: q2) { If (p==NULL) { Printf (" NULL \ r \ n "); } The else { Printf (" % d \ r \ n ", p - & gt; Id); } } }
CodePudding user response:
STL containers advice directly to store objects
CodePudding user response:
Record the index position, corresponding to delete