3

我在这里读了几行代码,在我看来应该有一些括号。

template<class InputIterator, class OutputIterator>
  OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result )
{
  while (first!=last) 
     *result++ = *first++; // <--- this line
  return result;
}

根据此处的运算符优先级表,我认为后缀增量优先,然后是取消引用,然后是赋值。但在我看来,其意图是首先发生取消引用,然后是赋值,然后是后缀增量。

我读错了吗?还是表格错了,还是代码片段错了?或者还有别的原因吗?

4

1 回答 1

6

后缀增量确实首先执行,但后缀增量的返回值是指针的原始值。这就是它起作用的原因。

于 2011-07-27T14:50:43.607 回答