未排序的修改警告在 C++11 中变为结果未使用警告
Unsequenced modification warning becomes result unused warning in C++11
我正在试验 this 过滤器库,并从以下代码片段中收到未排序的修改警告。
while (--numSamples >= 0)
*dest++ = state.process(*dest, *this);
在 SO 上查看类似问题是有道理的,因为 dest 是在同一个命令中修改和访问的。所以,我想预期的功能如下。 . .
while (--numSamples >= 0) {
*dest = state.process(*dest, *this);
*dest++;
}
但是,这为 post 增量提供了一个新的、更奇怪的警告 "warning: expression result unused"。为什么会出现这个新警告,我应该如何正确解决这个问题?
*dest++
递增 dest
,并取消引用 dest
的先前值。增量是您想要的副作用,取消引用无效。写成dest++
(或++dest
)即可。
我正在试验 this 过滤器库,并从以下代码片段中收到未排序的修改警告。
while (--numSamples >= 0)
*dest++ = state.process(*dest, *this);
在 SO 上查看类似问题是有道理的,因为 dest 是在同一个命令中修改和访问的。所以,我想预期的功能如下。 . .
while (--numSamples >= 0) {
*dest = state.process(*dest, *this);
*dest++;
}
但是,这为 post 增量提供了一个新的、更奇怪的警告 "warning: expression result unused"。为什么会出现这个新警告,我应该如何正确解决这个问题?
*dest++
递增 dest
,并取消引用 dest
的先前值。增量是您想要的副作用,取消引用无效。写成dest++
(或++dest
)即可。