使用“自动”。做什么的? [英] Usage of "auto". What for?

查看:63
本文介绍了使用“自动”。做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前被问及我对自动的使用情况。它的用途是什么?

关键字在这里显然是超级的。


与我写的绝大多数C / C ++开发人员相比

定义非常明确地表示:


int main(char argc,char * argv [],char * env []){

try {

auto Exception mainException(1);

mainException.setErrNo(42);

} catch(Exception caughtException){

std :: cout<< 抓住了抓住异常: << caughtException.errNo<<

std :: endl;

}

}


当然你不需要关键字auto来制作程序

编译,链接和运行。

另一方面,你(更清楚的解析器)获得简单的信息

关于定义的位置!

作为一名普通开发人员在编辑器中阅读他的C ++文件,其上面使用了

缩进很容易记住,当超出范围时,自动

变量将被解构。


另一方面,你可以使用代码例如,解析器更容易解决变量使用的问题。

I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:

int main(char argc, char *argv[], char *env[]) {
try {
auto Exception mainException(1);
mainException.setErrNo(42);
} catch (Exception caughtException) {
std::cout << "caught caughtException:" << caughtException.errNo <<
std::endl;
}
}

Of course you do not need the keyword auto to make the program
compile, link and run.
On the other hand, you (more clearly parsers) gain easy information
about where definitions are made !

As a plain developer reading his C++ file in an editor with the
indention used above it is mor ease to remember, that the auto
variables will be deconstructed, when going out of scope.

The other thing is, that you can use code parsers more easily to
process ascpects of variable usage for example.

推荐答案

" no ** *******@wanano.net" <到************** @ wanano.net写信息

新闻:11 **************** ******@q75g2000hsh.googlegr oups.com ...
"no*********@wanano.net" <To**************@wanano.netwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...

>我当前被问及我对auto的使用情况。它的用途是什么?

关键字在这里显然是超级的。


与我写的绝大多数C / C ++开发人员相比

定义非常明确地表示:
>I currently get asked about my usage of "auto". What is it for?
The keyword is clearly superflous here.

In contrast to the huge majority of C/C++ developers I write
definitions very explicitly like that:



然后你就可以享受待遇了:
http://www.open-std.org/jtc1/sc22/wg ... 2006 / n1984.pdf


切换到C ++ 09后,尽情享受重写代码的乐趣;)


- 西尔维斯特

Then you''re in for a treat:
http://www.open-std.org/jtc1/sc22/wg...2006/n1984.pdf

Have fun rewriting your code once you switch to C++09 ;)

- Sylvester


乍一看我真的很震惊。


似乎C ++的校长根本不感兴趣一个

稳定的语言。

Imho这是一个原因(除了缺少ABI

标准以允许交换C ++二进制库加上

标题),为什么C ++会像C#一样失去对语言的追随者对于

的例子。

标准对开发工作的保护越少,你就可以随时更改b $ b。

一个小型社区,表示降级语言。

当然,有中间技术可以连接不同的

语言。


但是有一个围绕软件开发的基础设施

(语言)没有通过连接技术解决,比如

程序员,库,工具,讨论,...

改变现有语言的语义和语法的想法

的特点是 - 非常礼貌地表达 - 对于

该语言的优势。

At first sight I am really horrified.

Seems the principals of C++ are not at all interested in having a
stable language.
I.m.h.o. this is one reason ( in addition to the lack of an ABI
standards to allow for exchange of C++ binary libraries plus
headers ), why C++ looses followers against languages as C# for
example.
The less protection of development efforts by the standard, the more
readily you change.

A small community of indicate the downgrade of a language.
Of course there is middle-technology to connect the different
languages.

But there is an infrastructure around software development
( languages ) that is not solved by connective techniques, like
programmers, libraries, tools, discussions, ...

The idea of changing semantics and syntax of existing language
features is - to express it very politely - not necessariliy to the
advantage of the language.


" no ********* @ wanano.net" <到************** @ wanano.net写信息

新闻:11 **************** ******@h2g2000hsg.googlegro ups.com ...
"no*********@wanano.net" <To**************@wanano.netwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...

乍一看我真的很震惊。


似乎C ++的校长对拥有

稳定语言并不感兴趣。

Imho这是一个原因(除了缺少ABI

标准以允许交换C ++二进制库加上

标题),为什么C ++会像C#一样失去对语言的追随者对于

的例子。
At first sight I am really horrified.

Seems the principals of C++ are not at all interested in having a
stable language.
I.m.h.o. this is one reason ( in addition to the lack of an ABI
standards to allow for exchange of C++ binary libraries plus
headers ), why C++ looses followers against languages as C# for
example.



我不同意。 C ++失去了追随者,因为C ++并没有像Java和C#那样迅速发展。此外,这个相同的自动功能也将使它成为C#3.0中的b $ b,所以根据你的推理,那些去C#代码的人将会停止使用C#来获取他们离开C ++也是一样的原因。

是的,你可以滥用新的''auto'功能,就像你可以滥用很多的c / b
一样功能,但对于那些处理大量通用代码和深层嵌套模板类型的人来说,这绝对是一个收获。我是一个人,很高兴这个新功能。我厌倦了每次写std :: vector< int> :: iterator

而且很明显,如果我在向量上调用begin()它会返回

非常相同类型(这只是一个轻微的滋扰)。


- 西尔维斯特

I don''t agree. C++ looses followers because C++ doesn''t evolve as rapidly as
Java and C#. Besides, this very same auto feature will also makes it way
into C# 3.0, so according to your reasoning those who went to code C# will
also stop using C# for the very same reason they left C++.

And yes, you can misuse the new ''auto'' feature just as you can misuse many
of the C++ features, but it''s definitely a gain for those who deal with lots
of generic code and deeply nested template types. I, for one, am happy of
the new feature. I''m tired of writing std::vector<int>::iterator every time
while it''s very obvious that if I call begin() on a vector it returns that
very same type (and this is just a mild nuisance).

- Sylvester


这篇关于使用“自动”。做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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