对象实例化快捷方式 [英] Object instantiation shortcuts

查看:84
本文介绍了对象实例化快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以允许对象实例化的扩展语法,所以

代替


Hashtable< string,int> table = new Hashtable< string,int>(10,10f);


我可以写:


Hashtable< string,int> table(10,10f);


这是可能的还是编译器不明确?


在某些情况下它会非常特别是在使用仿制药时很有用。


-

cody


[免费软件,游戏和幽默]
www.deutronium.de.vu || www.deutronium.tk

would it be possible to allow an extended syntax for Object instantiation so
that instead of

Hashtable<string,int> table = new Hashtable<string,int>(10, 10f);

I can write:

Hashtable<string,int> table(10, 10f);

Would this be possible or is this ambiguous to the compiler?

In some situations it would be very useful especially when using generics.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

推荐答案

cody< pl ************************* @ gmx.de>写道:
cody <pl*************************@gmx.de> wrote:
是否可以允许对象实例化的扩展语法,而不是

Hashtable< string,int> table = new Hashtable< string,int>(10,10f);

我可以写:

Hashtable< string,int> table(10,10f);

这是可行的还是编译器不明确?

在某些情况下,特别是在使用泛型时非常有用。
would it be possible to allow an extended syntax for Object instantiation so
that instead of

Hashtable<string,int> table = new Hashtable<string,int>(10, 10f);

I can write:

Hashtable<string,int> table(10, 10f);

Would this be possible or is this ambiguous to the compiler?

In some situations it would be very useful especially when using generics.




我真的希望这*不会发生 - 只是因为此刻,

当你''时,它非常清楚重新明确地创建一个新对象。打字数量的

差异真的那么重要吗?


-

Jon Skeet - < sk ** *@pobox.com>
http://www.pobox.com/~双向飞碟

如果回复小组,请不要给我发邮件



I really hope this *doesn''t* happen - simply because at the moment,
it''s very clear when you''re explicitly creating a new object. Is the
difference in the amount of typing really that important?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




"科迪" < PL ********** @ gmx.de>在消息中写道

新闻:OF ************** @ tk2msftngp13.phx.gbl ...

"cody" <pl*************************@gmx.de> wrote in message
news:OF**************@tk2msftngp13.phx.gbl...
是否可以允许对象实例化的扩展语法

而不是

Hashtable< string,int> table = new Hashtable< string,int>(10,10f);

我可以写:

Hashtable< string,int> table(10,10f);

这是可行的还是编译器不明确?

在某些情况下,特别是在使用泛型时非常有用。
would it be possible to allow an extended syntax for Object instantiation
so
that instead of

Hashtable<string,int> table = new Hashtable<string,int>(10, 10f);

I can write:

Hashtable<string,int> table(10, 10f);

Would this be possible or is this ambiguous to the compiler?

In some situations it would be very useful especially when using generics.




它可能但可能是不可取的。正如乔恩所说,它并没有使得新实例的创建成为可能,我认为它在C ++中有不同的含义

(本地或显式的堆栈构造)转换或其他东西,

它是C ++的一小部分内容之一我从来没有想过要帮助使语言变得非常复杂的




无论如何,一个不错的IDE修复了这个问题,vs2005已经自动插入

所有内容直到第一个(当你点击右键时(没有它)

infront of e e,不确定密钥)。这可能是一个工具问题更多

而不是语言一。我会告诉你,你不能总是使用IDE',但我

会怀疑你可以而且应该花费大部分时间。



Its possible but probably undesireable. As Jon said, it doesn''t make
creation of a new instance possible and I think it has a different meaning
in C++(stack construction of a local or explict conversions or something,
its one of those little tidbits of C++ I never got around to figuring out
that helps makes the language insanely complex).

Anyway, a decent IDE fixes this, vs2005 already automatically inserts
everything up to the first ( when you hit the right key(don''t have it
infront ofm e, not sure of the key). This is probably a "tools" problem more
so than a language one. I''ll give you that you can''t always use IDE''s, but I
would suspect most of hte time you can and should.


>它可能但可能是不可取的。


贡献愚蠢的建议是我的专业:)
> Its possible but probably undesireable.

Contribute stupid proposals are my specialitiy :)
正如乔恩所说,它没有'可以创建一个新的实例,我认为它在C ++中具有不同的含义(本地或显式转换的堆栈构造或其他东西,它是C ++的一小部分内容之一)我从来没有搞清楚
这有助于使语言变得非常复杂。)
As Jon said, it doesn''t make
creation of a new instance possible and I think it has a different meaning
in C++(stack construction of a local or explict conversions or something,
its one of those little tidbits of C++ I never got around to figuring out
that helps makes the language insanely complex).




我不确定你对显式转换的意思,但在C ++中语法

只调用给定变量的ctor。


-

cody


[免费软件,游戏和幽默]
www.deutronium.de.vu || www.deutronium.tk



Iam not sure what you mean with explicit conversion, but in C++ this syntax
only calls the ctor for the given variable.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


这篇关于对象实例化快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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