Announcement

Collapse
No announcement yet.

Error: was not declared in this scope

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error: was not declared in this scope

    Hallo Leute,

    ich habe obige Fehlermeldung bekommen, und ich weiß erhlich nicht wo mein Fehler liegt:

    Die Datei IndexWord.h
    Code:
    #include <string>
    #include <vector>
    
    #include "./File.h"
    
    // when the indexing starts, this class saves every word for a filename
    // (saved in Filelist and could be get through the id) and counts the
    // number of appearances in the file
    class IndexWord
    {
      public:
        // increases the number of this word in a file
        void increase();
    
        // Constructor, sets the word and id
        explicit IndexWord(std::string word, size_t id);
    
        // returns the word for which is made this index
        std::string getWord();
    
      private:
        // id of the parsed file
        size_t _id;
        // the word for which the file is indexed
        std::string _word;
        // number of appearances in the file
        size_t _number;
    };
    Die Datei IndexWord.cpp
    Code:
    #include <string>
    #include "./IndexWord.h"
    
    IndexWord::IndexWord(std::string word, size_t id)
    {
      _word = word;
      _id = id;
    }
    
    // _____________________________________________________________________________
    
    void IndexWord::increase()
    {
      _number++;
    }
    
    // _____________________________________________________________________________
    
    std::string getWord()
    {
      return _word;
    }
    Die Fehlermeldung, die ich bekomme:

    IndexWord.cpp: In function ‘std::string getWord()’:
    IndexWord.cpp:24:10: error: ‘_word’ was not declared in this scope
    IndexWord.cpp:25:1: warning: control reaches end of non-void function


    Wo liegt mein Fehler?
    http://forex-forum.eu/

  • #2
    _word = word;

    ist nirgendwo definiert.

    Die Methode
    getWord()
    ist keine Methode deiner Klasse IndexWord

    Die Zeiten, wo man Variablen mit _ schreibt sind lange vorbei.....
    Zuletzt editiert von Christian Marquardt; 08.08.2011, 16:22.
    Christian

    Comment

    Working...
    X