Auto SP0 =sprite::create (); Sp0->settag (0); auto SP1=sprite::create (); SP1->settag (1);//shared_ptr is used here, in your code, use the Stack object insteadstd::shared_ptr<vector<sprite*>> vec0 = std::make_shared<vector<sprite*>>(); VEC0-pushback (SP0); Vector<Sprite*> VEC1 (5); Vec1.insert (0, SP1); //You can also add a whole vectorVec1.pushback (*vec0); for(auto sp:vec1) {log ("Sprite Tag:%d", sp->Gettag ());} Vector<Sprite*> VEC2 (*vec0);if(vec0->equals (VEC2)) {Log ("VEC0==VEC2");}if(!Vec1.empty ()) { //to get the capacity and size of a vector, note that capacity is not necessarily equal to size if(vec1.capacity () = =vec1.size ()) {Log ("pvec1->capacity () ==pvec1->size ( )"); }Else{vec1.shrinktofit (); //shrinks the vector so that the memory corresponds to the number of elements, capacity is the capacity, and size is the number of elementsLog"pvec1->capacity () ==%d; Pvec1->size () ==%d", Vec1.capacity (), vec1.size ()); } //pvec1->swap (0, 1); //Exchange two elements in a vector by indexVec1.swap (Vec1.front (), Vec1.back ());//Exchange two elements in a vector by value if(Vec2.contains (SP0)) {//returns a Boolean value that indicates whether the object exists in the vectorLog"The index of SP0 in PVEC2 is%d", Vec2.getindex (SP0)); } //removing elements from a vectorvec1.erase (Vec1.find (SP0)); //pvec1->erase (1); //Pvec1->eraseobject (sp0,true); //Pvec1->popback ();vec1.clear ();//Remove all elementsLog"The size of PVEC1 is%d", Vec1.size ());}
Output:
10vec0= =vec2pvec1->capacity () = =2; Pvec1->size () = =2in was0is0
cocos2d-x3.x Vector