cocos2d-x3.x Vector

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.