我最近在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++的新手,所以请尽量不要把答案弄得太复杂。非常感谢大家。
auto是否也将maxIterator设为指针?
发布于 2014-01-20 12:50:51
编译器猜测maxIterator的类型。如果spec的类型为float [],则maxIterator类型为float *。
发布于 2014-01-20 13:01:42
在C++11中,关键字auto从其初始化表达式中推导出声明变量的类型。因此,在您的代码中,它推导出maxIterator的类型。
有关auto的更多信息,请查看here
https://stackoverflow.com/questions/21226402
复制相似问题