STL Vector problem

This is a discussion on STL Vector problem within the C++ Programming forums, part of the General Programming Boards category; 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"), ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

    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).

  2. #2
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    Weren't you pushing everything into 'gisInfoLayers' ???

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    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 .

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Formatting Using STL
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2004, 04:52 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. STL or no STL
    By codec in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2004, 02:36 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21