简体   繁体   English

在C ++ 11中,未排序的修改警告变为未使用的结果警告

[英]Unsequenced modification warning becomes result unused warning in C++11

I'm experimenting with this filters library, and getting an unsequenced modification warning from the following snippet. 我正在尝试使用过滤器库,并从以下代码段中收到无序的修改警告。

while (--numSamples >= 0)
    *dest++ = state.process(*dest, *this);

This makes sense looking at similar questions on SO, as dest is being modified and accessed in the same command. 当在同一命令中修改和访问dest时,在SO上查看类似的问题就很有意义。 So, I guess the intended functionality is the following . 因此,我想预期的功能如下。 . .

while (--numSamples >= 0) {
    *dest = state.process(*dest, *this);
    *dest++;
}

However, this gives a new, more curious warning "warning: expression result unused" for the post increment. 但是,这为发布增量给出了一个新的,更奇怪的警告“警告:表达式结果未使用”。 Why this new warning, and how should I fix this correctly? 为什么会出现此新警告,以及如何正确解决此问题?

*dest++ increments dest , and dereferences the prior value of dest . *dest++增量dest ,并且取消引用的先前值dest The increment is a side effect that you want, the dereference has no effect. 增量是所需的副作用,取消引用无效。 Just write it as dest++ (or ++dest ). 只需将其编写为dest++ (或++dest )即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM