GCC: Fehler in #include <string> & #include <fstream>



  • Hi,

    Ich benutze hier Dev-Cpp 4.9.8.0 samt mitgeliefertem GCC und
    habe hier den Prototypen einer Klasse für ein Spiel. Das dumme
    ist nur, dass das kompilieren dieser Klasse zu Fehlermeldungen
    führt welche scheinbar keinen Bezug zur Klasse haben.

    Mein Hauptproblem ist allerdings, dass ich dieses Schema (diese
    überladenen Operatoren, store-, restore-Methoden etc.) für
    mehrere Klassen verwende und bisher nie Probleme damit hatte.

    [1] Die betroffene Klasse

    #ifndef _WEAPONEFFECT_
    #define _WEAPONEFFECT_
    
    #include <fstream>
    #include "Creature.h"
    using namespace std;
    
    class WeaponEffect
    {
    public:
      WeaponEffect();
      ~WeaponEffect();
    
      WeaponEffect(int fd, int wd, int ed, int ad);
    
      inline int getFireDamage() { return m_iFire; }
      inline int getWaterDamage() { return m_iWater; }
      inline int getEarthDamage() { return m_iEarth; }
      inline int getAirDamage() { return m_iAir; }
      inline int getRace() { return m_iRace; }
      inline int getRaceDamage() { return m_iRaceDamage; }
    
      inline void setFireDamage(int f) { m_iFire = f; }
      inline void setWaterDamage(int w) { m_iWater = w; }
      inline void setEarthDamage(int e) { m_iEarth = e; }
      inline void setAirDamage(int a) { m_iAir = a; }
      inline void setRace(int r) { m_iRace = r; }
      inline void setRaceDamage(int r) { m_iRaceDamage = r; }
    
      bool operator==(WeaponEffect& rhs);
      WeaponEffect& operator=(WeaponEffect& rhs);
    
      int apply(Creature& target, int damage);
    
      ofstream& store(ofstream& out);
      ifstream& restore(ifstream& in);
    
    private:
      int m_iFire;       
      int m_iWater;      
      int m_iEarth;      
      int m_iAir;       
      int m_iRace;     
      // 0 := Keine
      // 1 := Untote
      // 2 := Orks
      // 3 := Drachen
      int m_iRaceDamage;
    };
    #endif
    
    #include "WeaponEffect.h"
    
    WeaponEffect::WeaponEffect()
    {
    }
    
    WeaponEffect::~WeaponEffect()
    {
      m_iFire = 0;
      m_iWater = 0;
      m_iEarth = 0;
      m_iAir = 0;
    }
    
    WeaponEffect::WeaponEffect(int fd, int wd, int ed, int ad)
    {
      m_iFire = fd;
      m_iWater = wd;
      m_iEarth = ed;
      m_iAir = ad;
    }
    
    bool WeaponEffect::operator==(WeaponEffect& rhs)
    {
      if (m_iFire == rhs.getFireDamage() &&
          m_iWater == rhs.getWaterDamage() && 
          m_iEarth == rhs.getEarthDamage() &&
          m_iAir == rhs.getAirDamage() &&
          m_iRace == rhs.getRace() &&
          m_iRaceDamage == rhs.getRaceDamage())
        return true;
      return false;
    }
    
    WeaponEffect& WeaponEffect::operator=(WeaponEffect& rhs)
    {
      if (this == &rhs) return *this;
      m_iFire = rhs.getFireDamage();
      m_iWater = rhs.getWaterDamage();
      m_iEarth = rhs.getEarthDamage();
      m_iAir = rhs.getAirDamage();
      m_iRace = rhs.getRace();
      m_iRaceDamage = rhs.getRaceDamage();
      return *this;
    }
    
    int WeaponEffect::apply(Creature& target, int damage)
    {
      damage += (m_iFire + m_iWater + m_iEarth + m_iAir);
      if (m_iRace == target.getRace()) 
      {
       damage += damage * (float)m_iRaceDamage / 100;
      }
      return damage;
    }
    
    ofstream& WeaponEffect::store(ofstream& out)
    {
      out.write((char*) &m_iFire, sizeof(m_iFire));
      out.write((char*) &m_iWater, sizeof(m_iWater));
      out.write((char*) &m_iEarth, sizeof(m_iEarth));
      out.write((char*) &m_iAir, sizeof(m_iAir));
      out.write((char*) &m_iRace, sizeof(m_iRace));
      out.write((char*) &m_iRaceDamage, sizeof(m_iRaceDamage));
      return out;
    }
    
    ifstream& WeaponEffect::restore(ifstream& in)
    {
      in.read((char*) &m_iFire, sizeof(m_iFire));
      in.read((char*) &m_iWater, sizeof(m_iWater));
      in.read((char*) &m_iEarth, sizeof(m_iEarth));
      in.read((char*) &m_iAir, sizeof(m_iAir));
      in.read((char*) &m_iRace, sizeof(m_iRace));
      in.read((char*) &m_iRaceDamage, sizeof(m_iRaceDamage));
      return in;
    }
    

    [2] Compiler Log

    Compiler: Default compiler
    Building Makefile: "C:\C++\Projekt31\Makefile.win"
    Führt make clean aus
    rm -f main.o Object.o Item.o Weapon.o CraftingStatus.o Tile.o Spell.o Creature.o Position.o Attributes.o Class.o Skills.o Race.o Stat.o WeaponEffect.o MagicWeapon.o Container.o Rune.o Event.o Armor.o Maplet.o ArmorEffect.o Resistances.o MagicArmor.o CombatSpell.o HealthSpell.o TransformationSpell.o TeleportationSpell.o TableFactory.o Projekt31.exe

    make.exe: *** Warning: File `main.cpp' has modification time in the future (2004-05-01 03:11:30 > 2004-04-01 16:50:57)

    g++.exe -c main.cpp -o main.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"

    g++.exe -c Object.cpp -o Object.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"

    g++.exe -c Item.cpp -o Item.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"

    g++.exe -c Weapon.cpp -o Weapon.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"

    g++.exe -c CraftingStatus.cpp -o CraftingStatus.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"

    g++.exe -c Tile.cpp -o Tile.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"

    g++.exe -c Spell.cpp -o Spell.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"

    g++.exe -c Creature.cpp -o Creature.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"

    g++.exe -c Position.cpp -o Position.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"

    g++.exe -c Attributes.cpp -o Attributes.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"

    g++.exe -c Class.cpp -o Class.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"

    g++.exe -c Skills.cpp -o Skills.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"

    g++.exe -c Race.cpp -o Race.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"

    g++.exe -c Stat.cpp -o Stat.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"

    g++.exe -c WeaponEffect.cpp -o WeaponEffect.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"

    In file included from C:/PROGRAMME/DEV-CPP/include/c++/iosfwd:45,
    from C:/PROGRAMME/DEV-CPP/include/c++/ios:44,
    from C:/PROGRAMME/DEV-CPP/include/c++/istream:44,
    from C:/PROGRAMME/DEV-CPP/include/c++/fstream:45,
    from WeaponEffect.h:9,
    from WeaponEffect.cpp:6:
    C:/PROGRAMME/DEV-CPP/include/c++/bits/stringfwd.h:46: syntax error before namespace' C:/PROGRAMME/DEV-CPP/include/c++/bits/stringfwd.h:51:char_traits' is not a
    template
    C:/PROGRAMME/DEV-CPP/include/c++/bits/stringfwd.h:59: parse error before `<'
    token

    C:/PROGRAMME/DEV-CPP/include/c++/bits/stringfwd.h:63: syntax error before `;'

    token
    C:/PROGRAMME/DEV-CPP/include/c++/bits/stringfwd.h:64: syntax error before ;' token In file included from C:/PROGRA~1/DEV-CPP/include/stddef.h:6, from C:/PROGRAMME/DEV-CPP/include/stddef.h:6, from C:/PROGRAMME/DEV-CPP/include/c++/cstddef:48, from C:/PROGRAMME/DEV-CPP/include/c++/cstdio:50, from C:/PROGRAMME/DEV-CPP/include/c++/bits/c++io.h:35, from C:/PROGRAMME/DEV-CPP/include/c++/bits/fpos.h:44, from C:/PROGRAMME/DEV-CPP/include/c++/iosfwd:46, from C:/PROGRAMME/DEV-CPP/include/c++/ios:44, from C:/PROGRAMME/DEV-CPP/include/c++/istream:44, from C:/PROGRAMME/DEV-CPP/include/c++/fstream:45, from WeaponEffect.h:9, from WeaponEffect.cpp:6: C:/PROGRA~1/DEV-CPP/lib/gcc-lib/mingw32/3.2/include/stddef.h:149: template declaration oftypedef int ptrdiff_t'
    C:/PROGRA~1/DEV-CPP/lib/gcc-lib/mingw32/3.2/include/stddef.h:149: confused by earlier errors, bailing out
    g++.exe -c MagicWeapon.cpp -o MagicWeapon.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"

    g++.exe -c Container.cpp -o Container.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"

    g++.exe -c Rune.cpp -o Rune.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"

    g++.exe -c Event.cpp -o Event.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"

    g++.exe -c Armor.cpp -o Armor.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"

    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"

    g++.exe -c ArmorEffect.cpp -o ArmorEffect.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"

    g++.exe -c Resistances.cpp -o Resistances.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"

    g++.exe -c MagicArmor.cpp -o MagicArmor.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"

    g++.exe -c CombatSpell.cpp -o CombatSpell.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"

    g++.exe -c HealthSpell.cpp -o HealthSpell.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"

    g++.exe -c TransformationSpell.cpp -o TransformationSpell.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"

    g++.exe -c TeleportationSpell.cpp -o TeleportationSpell.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"

    g++.exe -c TableFactory.cpp -o TableFactory.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"

    g++.exe main.o Object.o Item.o Weapon.o CraftingStatus.o Tile.o Spell.o Creature.o Position.o Attributes.o Class.o Skills.o Race.o Stat.o WeaponEffect.o MagicWeapon.o Container.o Rune.o Event.o Armor.o Maplet.o ArmorEffect.o Resistances.o MagicArmor.o CombatSpell.o HealthSpell.o TransformationSpell.o TeleportationSpell.o TableFactory.o -o "Projekt31.exe" -L"C:/PROGRAMME/DEV-CPP/lib"
    G__~1.EXE: WeaponEffect.o: No such file or directory

    make.exe: warning: Clock skew detected. Your build may be incomplete.

    Ausführung beendet

    Es tut mir Leid ein so langes Posting zu 'verbrechen' aber ich denke, dass mein
    Problem so am offensichtlichsten wird.

    Vielleicht kann mir ja jemand helfen 🙂

    Danke im Voraus,
    Khadgar

    EDIT: Thema durch. Ich nehm jetzt wieder VC (Der kann sich wenigstens artikulieren). Schliessen?



  • Lad dir mal nen neueren MinGW runter.
    Oder inkludiere mal <string> vor <fstream>

    btw: statt ifstream und ofstream würde ich lieber istream und ostream verwenden - so kann man auch in nicht dateien lesen und schreiben

    und sieh dir mal const an 😉



  • LOL. und warum implementierst du selbst Copykonstruktor und Zuweisungsoperator?


Anmelden zum Antworten