Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. erasing an element from a static vector.

erasing an element from a static vector.

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdata-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steph5
    wrote on last edited by
    #1

    Hi I have declared static vectors in a function that i call multiple times: static map<HWND, myVector<CString>> myMap; On some of the function calls i want to remove elements from a vector: myMap[hWindow].erase(iterator) where iterator pointers to the element in the array I want to remove. when I call myMap[hWindow].size() after erasing this element the size is the same as before?? Is this a consequences of using static vectors. Or am I doing something wrong????? More likely option 2 :laugh: but wanted to check with some one who knows more about this stuff. Many thanks

    M 1 Reply Last reply
    0
    • S steph5

      Hi I have declared static vectors in a function that i call multiple times: static map<HWND, myVector<CString>> myMap; On some of the function calls i want to remove elements from a vector: myMap[hWindow].erase(iterator) where iterator pointers to the element in the array I want to remove. when I call myMap[hWindow].size() after erasing this element the size is the same as before?? Is this a consequences of using static vectors. Or am I doing something wrong????? More likely option 2 :laugh: but wanted to check with some one who knows more about this stuff. Many thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      steph5 wrote:

      Is this a consequences of using static vectors.

      I don't think so.

      steph5 wrote:

      Or am I doing something wrong?

      I think so. I tried this:

      HWND hWindow = (HWND)1234;
      static std::map <HWND, vector <CString>> myMap;
      typedef pair <HWND, vector <CString>> myPair;
      vector <CString> myVector;
      myVector.push\_back(\_T("string 1"));
      myVector.push\_back(\_T("string 2"));
      myVector.push\_back(\_T("string 3"));
      myMap.insert(myPair(hWindow, myVector));
      vector <CString>::size\_type sizeBefore = myMap\[hWindow\].size();
      vector <CString>::iterator iterator;
      iterator = myMap\[hWindow\].begin();
      myMap\[hWindow\].erase(iterator);
      vector <CString>::size\_type sizeAfter = myMap\[hWindow\].size();
      

      sizeBefore is 3, sizeAfter is 2.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        steph5 wrote:

        Is this a consequences of using static vectors.

        I don't think so.

        steph5 wrote:

        Or am I doing something wrong?

        I think so. I tried this:

        HWND hWindow = (HWND)1234;
        static std::map <HWND, vector <CString>> myMap;
        typedef pair <HWND, vector <CString>> myPair;
        vector <CString> myVector;
        myVector.push\_back(\_T("string 1"));
        myVector.push\_back(\_T("string 2"));
        myVector.push\_back(\_T("string 3"));
        myMap.insert(myPair(hWindow, myVector));
        vector <CString>::size\_type sizeBefore = myMap\[hWindow\].size();
        vector <CString>::iterator iterator;
        iterator = myMap\[hWindow\].begin();
        myMap\[hWindow\].erase(iterator);
        vector <CString>::size\_type sizeAfter = myMap\[hWindow\].size();
        

        sizeBefore is 3, sizeAfter is 2.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S Offline
        S Offline
        steph5
        wrote on last edited by
        #3

        great got it working thanks for your help :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups