erasing an element from a static vector.
-
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
-
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
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:
-
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: