auto c++ 关键字有什么作用? [英] What does the auto c++ keyword do?
问题描述
我最近遇到了 C++ 中的关键字 auto.
I recently came accross the keyword auto in c++.
在代码中:
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-均衡器节拍检测和 bpm 估计/
This is to do with running a frequency analysis on a audio stream. From the website: http://katyscode.wordpress.com/2013/01/16/cutting-your-teeth-on-fmod-part-4-frequency-analysis-graphic-equalizer-beat-detection-and-bpm-estimation/
我已经搜索了论坛,但它说该关键字没有用.有人可以在这里解释一下它的用法吗.
I have searched the forums but It says that there is no use for the keyword. Could someone please explain the use of it here.
我对 C++ 很陌生,所以请尽量不要让答案太复杂.非常感谢大家.
I am quite new to c++ so please try not to make the answers too complicated. Thanks so much all.
自动使 maxIterator 也成为指针吗?
Did auto make maxIterator a pointer also?
推荐答案
在 C++11 中,关键字 auto
从其初始化表达式推导出声明变量的类型.因此,在您的代码中,它推导出 maxIterator
的类型.
In C++11, the keyword auto
deduces the type of declared variable from its initialization expression. Hence, in your code it deduces type of maxIterator
.
有关 auto
的更多信息,请查看此处一个>
For more information on auto
look here
这篇关于auto c++ 关键字有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!