简体   繁体   English

从未使用分配的值

[英]The assigned value is never used

Pretty sure the warning means that I declared a variable that I never used elsewhere but I'm almost positive I am using this variable.很确定警告意味着我声明了一个我从未在其他地方使用过的变量,但我几乎肯定我正在使用这个变量。

The line it highlights is:它突出显示的行是:

return fitIndex = ++i;

Yet if I remove the ++i my code behaves erroneously.但是,如果我删除++i我的代码就会出错。

If I do this instead:如果我这样做:

fitIndex = ++i;
return fitIndex;

It gives no warnings.它不发出任何警告。

Is there some interaction here with the return statement I'm missing?这里是否与我缺少的 return 语句有一些交互? Doesn't it increment i first, then assign it to fitIndex , and then returns the value?它不是先增加i ,然后将它分配给fitIndex ,然后返回值吗?

It doesn't affect my code at all, but just curious.它根本不影响我的代码,但只是好奇。

There doesn't seem to be any purpose to fitIndex (you never access the value, since you return immediately). fitIndex似乎没有任何目的(您永远不会访问该值,因为您立即返回)。 In other words, the compiler thinks换句话说,编译器认为

return fitIndex = ++i;

can be replaced by可以替换为

return ++i;

tl;dr you can remove fitIndex . tl;dr你可以删除fitIndex

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

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