我有一个双精度数组,需要对该数组进行计算,然后找到该计算产生的最小值和最大值。这基本上是我所拥有的:
double * array;
double result;
double myMin;
double myMax;
// Assume array is initialized properly...
for (int i = 0; i < sizeOfArray; ++i) {
result = transmogrify(array[i]);
if (i == 0) {
myMin = result;
myMax = result;
}
else if (result < myMin) {
myMin = result;
}
else if (result > myMax) {
myMax = result;
}
}
我收到一条警告说计算的值result
从未使用过,并且由于我们将所有警告都视为错误,因此无法编译。如何修复此代码以避免警告?我正在为我的编译器使用 g++。
这是警告文本:
cc1plus: warnings being treated as errors
foo.cc:<lineno of transmogrify call>: error: value computed is not used
编辑:我不明白反对票,但我现在已经开始工作了。感谢大家花时间帮助我。