auto c ++关键字有什么作用? [英] What does the auto c++ keyword do?

查看:242
本文介绍了auto c ++关键字有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在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; });

这与对音频流进行频率分析有关. 从网站上:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆