Thread: When it comes to the STL, i'm an idiot.

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    When it comes to the STL, i'm an idiot.

    m_surfaceList is defined as std::list<CSurfaceList>
    This routine is supposed to search the surface list for a particular index number, if it's found, it's returned. If not, it's created, pushed on and returned.

    CSurfaceList is defined as:
    Code:
    struct CSurfaceList
    {
         Uint32 index;
         CSurface surface;
    }
    PHP Code:
    SDL_Surface *CPalette::GetImg(Uint16 iTileNum) const
    {
        
    std::list<CSurfaceList>::iterator findIterator;
    ->    
    for (findIterator m_surfaceList.begin(); findIterator != m_surfaceList.end(); findIterator++)
        {
            if (
    findIterator->index == iTileNum)    // Did we find it
            
    {
                return 
    findIterator->surface.GetSurface();    // It's found, return it
            
    }
        }
        
    CSurfaceList returnSurface;

        
    SDL_Rect rSrc = {    // The dimensions and offsets of the tile we need in the main palette
                            
    (iTileNum m_imgInfo.iEntriesPerLine) * m_imgInfo.iWidth
                            (
    iTileNum % (m_imgInfo.iTotalEntries m_imgInfo.iEntriesPerLine)) * m_imgInfo.iHeight,
                            
    m_imgInfo.iWidth
                            
    m_imgInfo.iHeight 
                        
    };
            
        
    returnSurface.surface.SetSurface(m_pPalette, &rSrc);    // Set the surface
    ->    m_surfaceList.push_back(returnSurface);                    // Put it on the end of the list

        
    return returnSurface.surface.GetSurface();
    }; 
    And the errors...
    CPalette.cpp(223) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::list<struct CSurfaceList,class std::allocator<struct CSurfaceList>
    >::const_iterator' (or there is no acceptable conversion)
    CPalette.cpp(223) : error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'class std::list<struct CSurfaceList,class std::allocator<struct CSurfaceList>
    >::iterator' (or there is no acceptable conversion)
    CPalette.cpp(240) : error C2662: 'push_back' : cannot convert 'this' pointer from 'const class std::list<struct CSurfaceList,class std::allocator<struct CSurfaceList> >' to 'class std::
    list<struct CSurfaceList,class std::allocator<struct CSurfaceList> > &'
    Conversion loses qualifiers

    -> indicates the line on which the error occoured.
    Any help would be appreciated.
    Last edited by Eibro; 10-24-2002 at 11:11 PM.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Because you are changing member varaibles, the function shouldn't be declared const.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Awww jesus. The function worked it a completly different way before, which didn't change the member variables. Funny how the errors told nothing about why the problem was occouring. Or maybe it was a case of the untrained eye?

    Oh, and thanks.
    Last edited by Eibro; 10-25-2002 at 08:07 AM.

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, 05: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