【发布时间】:2016-10-13 21:59:07
【问题描述】:
在尝试定义“列表”以了解 C++ 列表如何按照 Stroustrup 的书 PPP 2nd ed 工作时。 刚刚出现了一个名为“other”的来历不明的词,我认为“other”这个词只是一个类 Text_iterator 对象的名称,但我不太明白它的用途。它是否试图将整个文本与另一个文本进行比较,以考虑打开不同文本的可能性?
class Text_iterator { // keep track of line and character position within a line
list<Line>::iterator ln;
Line::iterator pos;
public:
// start the iterator at line ll’s character position pp:
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); }
};
Text_iterator& Text_iterator::operator++()
{
++pos; // proceed to next character
if (pos==(*ln).end()) {
++ln; // proceed to next line
pos = (*ln).begin(); // bad if ln==line.end(); so make sure it isn’t
}
return *this;
}
【问题讨论】:
-
你能不能...缩进你的代码?
-
它是缩进的,选择和转换为代码的工具就是这样