auto c++关键字是什么?

4

我最近接触到了C++中的关键字auto。

在以下代码中:

auto maxIterator = std::max_element(&spec[0], &spec[sampleSize]);
float maxVol = *maxIterator;

// Normalize
if (maxVol != 0)
  std::transform(&spec[0], &spec[sampleSize], &spec[0], [maxVol] (float dB) -> float { return dB / maxVol; });

这涉及对音频流进行频率分析。 从这个网站上获取:http://katyscode.wordpress.com/2013/01/16/cutting-your-teeth-on-fmod-part-4-frequency-analysis-graphic-equalizer-beat-detection-and-bpm-estimation/ 我已经在论坛中搜索,但是它说关键字没有用。有人能解释一下这里的用途吗?
我对c ++比较新,请尽量不要让答案太复杂。
谢谢大家。
自动将maxIterator指针化了吗?

1
https://dev59.com/H2sz5IYBdhLWcg3w6MRS?rq=1 - chris
2个回答

2

编译器猜测 maxIterator 的类型。如果 spec 的类型是 float [],则 maxIterator 的类型为 float *


2
在C++11中,关键字auto从其初始化表达式推断出已声明变量的类型。因此,在您的代码中,它推断出maxIterator的类型。
有关auto的更多信息,请查看这里

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接