Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前正在为内部数据结构实现迭代器,并查看了 QVector 如何实现其迭代器。我不明白为什么 QTypedArrayData::iterator 实现了它的 ++ 和 -- 运算符,例如:
T *i; inline iterator &operator++() { ++i; return *this; } inline iterator &operator--() { i--; return *this; }
我不明白的是两者之间的差异:为什么它使用后缀减量运算符?
感谢您的澄清!
您缺乏理解意味着期望两者之间存在任何实际差异,并且编码是故意以这种方式完成的。这种期望是合理的,但却是不正确的。你可以用任何一种方式编写这些操作,它们的工作原理是一样的。这对于复制/移动成本高昂的非 POD 类型可能很重要,但此处并非如此。15到20 年前,它对那个时代糟糕的编译器很重要。谢天谢地,我们不必再处理 VS6 了 :)