新手刚开始学c++ 看到教程里有用到&&这种声明变量的方式,搞不清楚是什么状况,请教一下。。
array arr{1.1, 2.2, 3.3, 4.4, 5.5};
float total = 0.0;
for (float value : arr) total += value;
total = 0.0;
for (float &value : arr) total += value;
total = 0.0;
for (auto &&value : arr) total += value;
上面的代码,在循环里输出value的值是一样的,total的值也是一样的,这三种方式写的话,区别在哪里?
最后一个 &&value 为什么不能用float?会报错