Fehler im Konstruktor



  • Tach, folgendes

    mmlexer.hpp

    #ifndef __MMLEXER_HPP__
    #define __MMLEXER_HPP__
    
    #include <string>
    #include <istream>
    #include <queue>
    #include "mmutils.hpp"
    
    namespace MM {
    
      typedef enum {
        tokAdd = '+',
        tokSub = '-',
        tokMul = '*',
        tokDiv = '/',
        tokPow = '^',
        tokFac = '!',
    
        tokAsn = '=',
        tokOPr = '(',
        tokCPr = ')',
        tokOCP = '{',
        tokCCP = '}',
        tokSep = ';',
        tokCom = ',',
        tokPrt = '>',
    
        tokIdr,
        tokVal
      } TokenType;
    
      class Lexer {
        public:
          typedef struct {
            unsigned type;
            double value;
            std::string identifier;
          } Token;        
          Lexer(std::istream&, bool, bool);
          bool Parse();
          bool IsParsed() const;
          bool NextToken(Token&);
        private:
          std::istream m_src;
          std::queue<Token> m_data;
          bool m_otf;
          bool m_debug;
          bool m_parsed;
          bool GetToken(Token&);
      };
    
    }
    
    #endif //__MMLEXER_HPP__
    

    mmlexer.cpp

    #include "mmlexer.hpp"
    
    bool MM::Lexer::GetToken(Token& token) {
      char ch;
      do {
        if (!m_src.get(ch)) {
          token.type = tokSep;
          return false;
        };
      } while (is_space(ch) || is_cntrl(ch));
      switch (ch) {
        case tokAdd:
        case tokSub:
        case tokMul:
        case tokDiv:
        case tokPow:
        case tokFac:
        case tokAsn:
        case tokOPr:
        case tokCPr:
        case tokOCP:
        case tokCCP:
        case tokSep:
        case tokCom:
        case tokPrt:
          token.type = ch;
          return true;
        default:
          if (is_letter(ch)) {
            token.identifier += ch;
            while (m_src.get(ch) && is_letter(ch))
              token.identifier += ch;
            token.type = tokIdr;
            return true;
          };
          if (is_digit(ch)) {
            m_src.putback(ch) >> token.value;
            token.type = tokVal;
            return true;
          };
      };
      return false;
    }
    
    bool MM::Lexer::NextToken(Token& token) {
      bool result;
      if (m_otf) {
        result = GetToken(token);
      }
      else {
        if (result = m_data.size()) {
          token = m_data.front();
          m_data.pop();
        };
      };
      return result;
    }
    
    bool MM::Lexer::Parse() {
      if (m_otf)
        {
          Token token;
          clear_queue<Token>(m_data);
          while (GetToken(token))
            m_data.push(token);
          return true;
        };
      return false;
    }
    
    MM::Lexer::Lexer(std::istream& src, bool otf, bool debug)
    : m_src(src), m_otf(otf), m_debug(debug), m_parsed(false) {
      m_parsed = Parse();
    }
    
    bool MM::Lexer::IsParsed() const {
      return m_parsed;
    }
    

    C:/Programme/DevCpp/include/c++/3.4.2/bits/ios_base.h: In copy constructor std::basic\_ios<char, std::char\_traits<char> >::basic\_ios(const std::basic\_ios<char, std::char\_traits<char> >&)': C:/Programme/DevCpp/include/c++/3.4.2/bits/ios\_base.h:738: error:std::ios_base::ios_base(const std::ios_base&)' is private
    mmlexer.cpp:72: error: within this context

    Die Meldung "mmlexer.cpp:72: error: within this context" verweist auf den Konstruktor von Lexer in mmlexer.cpp. Ich hab schon ewig im Netz rumgesucht, aber einfach keinen Hinweis auf die Problemlösung gefunden! Ich hoffe mir kann jemand helfen, denn es kann eigentlich nichts kompliziertes sein.

    MfG && Thx



  • du hältst dir doch wohl hoffentlich keine streams als member? das ist nämlich pfui-gack



  • Tach...

    nein, nur als Referenz 😉 ... Wo liegt der Fehler bzw. wie kann ichs besser machen???

    MfG



  • class Lexer
    {
      ...
    private:
      std::istream m_src;
    }
    

    Das sieht mir überhaupt nicht nach einer Referenz aus 😉 Richtig sollte es heißen:

    std::istream& m_src;
    

Anmelden zum Antworten