Kompilieren von std::map - Wrapper schlägt auf merkwürdige Art fehl.



  • Guten Morgen zusammen,

    Der folgende Code erzeugt Kompilerfehler bezüglich der "stl_tree.h"
    und "stl_map.h" welche ich mir nicht erklären kann, da DevCpp
    erstaunlicherweise keine Fehlerstellen in meinem Code sondern nur in den
    stl-Daten findet.
    Mir fehlt einfach total der Anhaltspunkt 😞

    [1] Das Kompiler-Log

    Compiler: Default compiler
    Building Makefile: "C:\C++\Projekt31\Makefile.win"
    Führt make... aus
    make.exe -f "C:\C++\Projekt31\Makefile.win" Maplet.o
    g++.exe -c Maplet.cpp -o Maplet.o -I"C:/PROGRAMME/DEV-CPP/include/c++" -I"C:/PROGRAMME/DEV-CPP/include/c++/mingw32" -I"C:/PROGRAMME/DEV-CPP/include/c++/backward" -I"C:/PROGRAMME/DEV-CPP/include"

    C:/PROGRAMME/DEV-CPP/include/c++/bits/stl_function.h: In member function bool std::less<\_Tp>::operator()(const \_Tp&, const \_Tp&) const [with \_Tp = Position]': C:/PROGRAMME/DEV-CPP/include/c++/bits/stl\_tree.h:1271: instantiated fromstd::_Rb_tree_iterator<_Val, _Val&, _Val*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::find(const _Key&) [with _Key = Position, _Val = std::pair<const Position, Container>, _KeyOfValue = std::_Select1st<std::pair<const Position, Container> >, _Compare = std::less<Position>, _Alloc = std::allocator<std::pair<const Position, Container> >]'
    C:/PROGRAMME/DEV-CPP/include/c++/bits/stl_map.h:332: instantiated from std::\_Rb\_tree<\_Key, std::pair<const \_Key, \_Tp>, std::\_Select1st<std::pair<const \_Key, \_Tp> >, \_Compare, \_Alloc>::iterator std::map<\_Key, \_Tp, \_Compare, \_Alloc>::find(const \_Key&) [with \_Key = Position, \_Tp = Container, \_Compare = std::less<Position>, \_Alloc = std::allocator<std::pair<const Position, Container> >]' Maplet.h:41: instantiated from here C:/PROGRAMME/DEV-CPP/include/c++/bits/stl_function.h:197: no match forconst
    Position& < const Position&' operator

    Ausführung beendet

    [2] Maplet.h

    #ifndef _MAPLET_
    #define _MAPLET_
    
    #define DIMENSION 50
    
    #include <fstream>
    #include <map>
    #include "Position.h"
    #include "Container.h"
    using namespace std;
    
    class Maplet
    {
    public:
      Maplet();
      ~Maplet();
    
      Maplet(int x, int y);
    
      inline int getGraphic(int x, int y) 
      {
        int res = -1 ;
        if (x <= DIMENSION && y <= DIMENSION) 
          res = m_Layer[x][y];
        return res; 
      }
    
      inline void setGraphic(int x, int y, int i) 
      { 
        if (x <= DIMENSION && y <= DIMENSION) 
        m_Layer[x][y] = i;
      }
    
      inline bool insertItem(Position& p, Item& i)
      {
        if ((m_Iter = m_Items.find(p)) != m_Items.end())
        {
          if (m_Iter->second.add(i)) return true;
        }
        return false;    
      }
    
      inline Item& getItem(Position& p, Item& hand)
      {
        if ((m_Iter = m_Items.find(p)) != m_Items.end())
        {
          Container c = m_Iter->second;
          hand = c.get(c.getSize());
          c.remove(c.getSize());
          return hand;
        }
        return m_Dummy;
      }
    
      bool operator==(Maplet& rhs);
      Maplet& operator=(Maplet& rhs);
    
      ofstream& store(ofstream& out);
      ifstream& restore(ifstream& in); 
    
    private:
      int m_Layer[DIMENSION][DIMENSION];
      map<Position, Container> m_Items;
      map<Position, Container>::iterator m_Iter;
      Item m_Dummy;
    };
    #endif
    

    [3] Maplet.cpp

    #include "Maplet.h"
    
    Maplet::Maplet()
    {
      for (int i = 0; i < DIMENSION; i++)
      {
        for (int j = 0; j < DIMENSION; j++)
        {
          m_Layer[j][i] = 0;
        }
      }
    }
    
    Maplet::~Maplet() {}
    
    bool Maplet::operator==(Maplet& rhs)
    {
      for (int i = 0; i < DIMENSION; i++)
      {
        for (int j = 0; j < DIMENSION; j++)
        {
          if (m_Layer[j][i] != rhs.getGraphic(j, i)) return false;
        }
      }
      return true;
    }
    
    Maplet& Maplet::operator=(Maplet& rhs)
    {
      if (*this == rhs) return *this;
      for (int i = 0; i < DIMENSION; i++)
      {
        for (int j = 0; j < DIMENSION; j++)
        {
          m_Layer[j][i] = rhs.getGraphic(j, i);
        }
      }
      return *this;
    } 
    
    ofstream& Maplet::store(ofstream& out)
    {
      for (int i = 0; i < DIMENSION; i++) {
        for (int j = 0; j < DIMENSION; j++) {
          out.write((char*) &m_Layer[j][i], sizeof(m_Layer[j][i]));
        }
      }
      return out;
    }
    
    ifstream& Maplet::restore(ifstream& in)
    {
      for (int i = 0; i < DIMENSION; i++) {
        for (int j = 0; j < DIMENSION; j++) {
          in.read((char*) &m_Layer[j][i], sizeof(m_Layer[j][i]));
        }
      }
      return in;
    }
    

    Danke im Voraus,
    Khadgar



  • Ich tippe: Position hat keinen op<, bzw. keinen für 2 konstante Objekte.



  • Schande über mich.
    Dabei war ich sicher alle notwendigen Operatoren schon vor Ewigkeiten
    implementiert zu haben.

    Vielen Dank!!


Anmelden zum Antworten