-
STL Vector problem
I use a vector to store data:
Code:
vector<CMapLayer> gisInfoLayers;
gisInfoLayers.push_back(CMapLayer(_T("Huidige positie"), _T("c01s01"), _T("c01s01icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Track"), _T("c01s02"), _T("c01s02icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Stadsdeel"), _T("c01s03"), _T("c01s03icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Straten"), _T("c01s04"), _T("c01s04icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Plein&Markt"), _T("c01s05"), _T("c01s05icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Park&Tuin"), _T("c01s06"), _T("c01s06icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Water"), _T("c01s07"), _T("c01s07icon"), true));
gisInfoLayers.push_back(CMapLayer(_T("Spoorweg"), _T("c01s08"), _T("c01s08icon"), true));
Categories.push_back(CMapCategory(_T("c01icon"), _T("Geografische info"), _T("c01"), true, false, gisInfoLayers));
When I do the following:
Code:
Categories.at(iCount1).Layers.at(iCount2).GetName();
I always get Geografische info, instead of Stadsdeel, Straten, and so on. Why is that? (iCount are counters in for loops).
-
Weren't you pushing everything into 'gisInfoLayers' ???
-
Yes. Categories contains CMapCategory object, and each CMapCategory object contains a vector with CMapLayer objects. But I've solved the problem now: constructor and operator= were incorrect. vector apperantly has built-in operator= (and other operators) so I used those to assign vectors. Starting to like STL :).
-
In fact, if all your member variables copy themselves correctly (which should usually be the case if you are using standard library tools) then you don't need a copy constructor and copy assignment operator at all. It can be better to not write them and just leave a comment that all members copy themselves correctly. This makes it more difficult to forget to add a new member to those methods.