Error C3646: Unknown override specifier
I teach C++ from the book, at the end of the chapter there are tasks and one of them is to make a function for counting characters in the Document class. When creating the class, a problem occurred: when starting the program, the error "C3646 begin: unknown definition specifier" appears. Same error with the end () function;
Document.h:
#include <list>
#include <vector>
#include <iostream>
using namespace std;
using Line = vector<char>;
struct Document {
list<Line> line;
Document() { line.push_back(Line{}); }
Text_iterator begin() { return Text_iterator(line.begin(), line.begin()->begin()); } //здесь ошибка
Text_iterator end() { return Text_iterator(line.end(), line.end()->end()); } //в этой строке так же
int count();
};
istream& operator>> (istream& is, Document& d) {
for (char ch; is.get(ch);) {
d.line.back().push_back(ch);
if (ch == '\n') d.line.push_back(Line{});
}
if (d.line.back().size()) d.line.push_back(Line{});
return is;
}
class Text_iterator {
list<Line>::iterator ln;
Line::iterator pos;
public:
Text_iterator (list<Line>::iterator ll, Line::iterator pp) : ln{ll}, pos{pp} {}
char& operator* () { return *pos; }
Text_iterator& operator++ ();
bool operator== (const Text_iterator& other) const { return ln == other.ln && pos == other.pos; }
bool operator!= (const Text_iterator& other) const { return !(*this == other); }
};
0
Author: Alexen Mort, 2017-08-20
1 answers
Well, how does the compiler know what is Text_iterator
before its announcement?
Move the Text_iterator
class declaration before the Document
class.
I only answered your specific question; I didn't check whether everything will work correctly after that...
1
Author: Harry, 2017-08-20 14:06:12