空论点 [英] Empty arguments

查看:50
本文介绍了空论点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨组,

差不多3个星期前我在这里和comp.std.c ++发布了一个简短的问题

我得到了Kevin Goodsell的1个响应。他说他不想要它的价值。我在这里再次发布它,这次是在一个名为''Empty arguments''的帖子中,因为

就是我从你那里得到的。你可以花一点时间试着看看我的观点吗?


struct Room

{

房间(bool a = true, bool b = true,bool c = true):椅子(a),表(b),床(c){}

bool椅子,桌子,床;

};

int main()

{

房间卧室; //椅子,桌子,床

房间居住(,,假); //没有生活床位

客房(假,); //椅子,床,没有桌子,没有自来水

房间厕所(,假,假); //没有桌子,没有床

返回0;

}


上述参数的缺陷使用是一个微不足道的案例。我在函数调用中填充了我的

Windows结构,并为每个

正式参数赋予一个默认值。我想更加精细地使用默认的

参数,但是由于C ++不允许

空参数,我受到阻碍。

对于任何数量和参数组合,空参数将使您拥有一个构造函数或函数

。您只能在非默认值中填写

,并使用相应的

数字的逗号分隔它们。


这个代码的语义很容易理解,但C ++中允许的语法不是
。 Annotated C ++参考手册:


< ARM 8.2.6>

有人觉得空论点很重要不是

只是太微妙,但严重减少了检测错误的机会

;参数列表中的额外逗号是

不是打字错误或编辑草率不正常的结果。

< />


我不同意它太微妙了。这只是计算逗号'

的问题。我确实觉得有些冒犯,但是我的草率打字预计

语言。对于更灵活的默认参数,确实需要

。没有

的原因还不够令人信服。

-----------


为什么没有人打开他的打字机,想一些事情

烦人片刻并输入


你不会多得多!它太快了#@%ING简单!!!!


或类似的东西。它会比不存在的回复更好

到现在为止。


谢谢,


-X

解决方案

代理人Mulder写道:

嗨组,
差不多3个星期前我在这里发了一个简短的问题在comp.std.c ++
中我得到了Kevin Goodsell的1个响应。他说他不想要它。我在这里再次发布它,这次是在一个名为''Empty
arguments''的帖子中,因为这就是我从你那里得到的。你可以节省一分钟并试着看看我的观点吗?

结构房间
{
房间(bool a = true,bool b = true,bool c = true):椅子(a),表(b),床(c){}
bool椅子,桌子,床;
};
int main()
{
房间卧室; //椅子,桌子,床
房间生活(,,假); //没有床在客厅
客房(假,); //椅子,床,没有桌子,没有跑步

房间厕所(,假,假); //没有桌子,没有床
返回0;
}

以上论点的缺陷使用是一个微不足道的案例。我在函数调用中填充了我的
Windows结构,并为每个
形式参数提供了一个默认值。我想对错误的
参数进行更详细的使用,但是C ++不允许空参数这一事实阻碍了我。

空参数会让你拥有一个构造函数或函数
用于任何数量和参数组合。您必须只填写非默认值并使用相应的逗号数字分隔它们。

这段代码的语义很容易理解,但语法很简单在C ++中是不允许的。 Annotated C ++参考手册:

< ARM 8.2.6>
有人认为空洞的论点很重要并不是太微妙,而是严重减少了机会。 />用于检测错误;参数列表中的额外逗号不是打字错误或编辑草率不正常的结果。
< />

我不同意它也是如此微妙。这只是计算逗号的问题。我确实感到有些冒犯,然而
语言预示着我的草率打字。对于更灵活的默认参数,确实需要
。没有它们的理由不够令人信服。
-----------


你不明白,那没问题。但这正是为什么不允许使用
空参数的原因。因为在一个函数中有很多参数

,默认值为5个逗号,一个值和4个逗号,一个值最终可能是

对编译器都是正确的,但对运行时没有。并且发现错误

是微妙的。


BTW如果你对微软定义他们的Windows

结构的方式感到沮丧..好吧,你需要在那里抱怨。

为什么没有人打开他的打字机,想一些令人讨厌的东西并输入

你好吗? '多得多!它太过简单了!@%ING简单!!!!

或类似的东西。到现在为止,它会比不存在的
回复更好。




据我所知,你得到的所有回复都是你支付的。


-

阿提拉又名WW


代理Mulder写道:

你好小组,
差不多3个星期前我在这里和comp.std.c ++中发布了一个简短的问题
我得到了Kevin Goodsell的1个响应。他说他不想要它。我在这里再次发布它,这次是在一个名为''Empty arguments''的帖子中,因为
就是我从你那里得到的。你可以花一点时间试着看看我的观点吗?




捐了一分钟。


我不相信对默认参数的扩展将提供任何进一步的可读性或显着降低新代码的复杂性。


而不是让程序员更难以标准化/>
理解,我宁愿看到它变得更简单。


我也会回应错别字。


< Gianni Mariani>

我不相信默认参数的扩展将提供任何进一步的可读性或显着降低新代码的复杂性。
而不是让程序员更难理解标准,我宁愿看到它变得更简单。



< />


你不必使用它。你可以很容易地把这些丑陋的东西包起来,比如

这个:


void ugly(int a = 0,bool b = true,char c =''D '',string d =" Hello World"){}

void ugly(string a){ugly(,,,);}


并且像这样使用


丑陋(再见世界);


逗号计数部分令人困惑,这是真的。在第一版

丑陋的参数列表中只有三个逗号'

。 C ++的语法允许您跳过逗号'

后面没有实际参数。当然,在重写之前的逗号'

很重要。


有可能出现歧义,但它可能会被逼到绝境中

的语法如下:


丑(int,bool,char,告别);


-X


Hi group,
Almost 3 weeks ago I posted a short question here and in comp.std.c++
and I got exactly 1 respons, from Kevin Goodsell. He said he didn''t want
it. I post it here again, this time in a thread named ''Empty arguments'', because
that is what I got from you. Can you spare a minute and try to see my point?

struct Room
{
Room(bool a=true,bool b=true,bool c=true):Chair(a),Table(b),Bed(c){}
bool Chair,Table,Bed;
};
int main()
{
Room bedroom; //chair, table, bed
Room living(,,false); //no bed in the living
Room guestroom(,false,); //chair, bed, no table, no running water
Room toilet(,false,false); //no table, no bed
return 0;
}

The defective use of arguments above is a trivial case. I fill my
Windows structs in a function call and give a default value to each
formal argument. I want to apply a more elaborate use of default
arguments, but I am hindered by the fact that C++ does not allow
empty arguments.

Empty arguments would enable you to have one constructor or function
for whatever number and combination of arguments. You must only fill
in the non-default values and seperate them with the appropriate
number of comma''s.

The semantics of this code is easily understood but the syntax is not
allowed in C++. The Annotated C++ Reference Manual:

<ARM 8.2.6>
It was felt that having empty arguments significant was not
only too subtle, but seriously decreased the opportunities
for detecting errors; an extra comma in an argument list is
not an unusual result of bad typing or sloppy editing.
</>

I don''t agree on it being too subtle. It''s only a matter of
counting comma''s. I do feel a little offended however that the
language anticipates on my sloppy typing. There is a real need
for more flexible default arguments. The reasons not to have
them are not convincing enough.
-----------

Why does nobody fire up his typewriter, think about something
annoying for a moment and type

YOU WON''T GET IT MULDER!!! IT''S TOO F#@%ING SIMPLE !!!!

or something along those lines. It will be better than non-existant replies
till now.

Thank you,

-X

解决方案

Agent Mulder wrote:

Hi group,
Almost 3 weeks ago I posted a short question here and in comp.std.c++
and I got exactly 1 respons, from Kevin Goodsell. He said he didn''t
want
it. I post it here again, this time in a thread named ''Empty
arguments'', because that is what I got from you. Can you spare a
minute and try to see my point?

struct Room
{
Room(bool a=true,bool b=true,bool c=true):Chair(a),Table(b),Bed(c){}
bool Chair,Table,Bed;
};
int main()
{
Room bedroom; //chair, table, bed
Room living(,,false); //no bed in the living
Room guestroom(,false,); //chair, bed, no table, no running
water
Room toilet(,false,false); //no table, no bed
return 0;
}

The defective use of arguments above is a trivial case. I fill my
Windows structs in a function call and give a default value to each
formal argument. I want to apply a more elaborate use of default
arguments, but I am hindered by the fact that C++ does not allow
empty arguments.

Empty arguments would enable you to have one constructor or function
for whatever number and combination of arguments. You must only fill
in the non-default values and seperate them with the appropriate
number of comma''s.

The semantics of this code is easily understood but the syntax is not
allowed in C++. The Annotated C++ Reference Manual:

<ARM 8.2.6>
It was felt that having empty arguments significant was not
only too subtle, but seriously decreased the opportunities
for detecting errors; an extra comma in an argument list is
not an unusual result of bad typing or sloppy editing.
</>

I don''t agree on it being too subtle. It''s only a matter of
counting comma''s. I do feel a little offended however that the
language anticipates on my sloppy typing. There is a real need
for more flexible default arguments. The reasons not to have
them are not convincing enough.
-----------
You don''t understand it, that is OK. But this is exactly the point why
empty arguments are not allowed. Since in a function having many arguments
with defaults 5 commas and a value and 4 commas and a value could end up be
both correct for the compiler, but not for runtime. And finding that error
is subtle.

BTW if you are frustrated by the way Microsoft defines their Windows
structure... well, you will need to complain there.
Why does nobody fire up his typewriter, think about something
annoying for a moment and type

YOU WON''T GET IT MULDER!!! IT''S TOO F#@%ING SIMPLE !!!!

or something along those lines. It will be better than non-existant
replies till now.



As far as I see you gave got all replies you have payed for.

--
Attila aka WW


Agent Mulder wrote:

Hi group,
Almost 3 weeks ago I posted a short question here and in comp.std.c++
and I got exactly 1 respons, from Kevin Goodsell. He said he didn''t want
it. I post it here again, this time in a thread named ''Empty arguments'', because
that is what I got from you. Can you spare a minute and try to see my point?



Donated a minute.

I don''t believe that extensions to default arguments will provide any
further readability or significant reduced complexity of new code.

Instead of making the standard more difficult for programmers to
understand, I''d rather see it become simpler.

I''ll also echo the point on typos.


<Gianni Mariani>

I don''t believe that extensions to default arguments will provide any
further readability or significant reduced complexity of new code.
Instead of making the standard more difficult for programmers to
understand, I''d rather see it become simpler.


</>

You don''t have to use it. And you can easily wrap up the uglies like
this:

void ugly(int a=0,bool b=true,char c=''D'',string d="Hello World"){}
void ugly(string a){ugly(,,,a);}

and use it like this

ugly("Goodbye World");

The comma counting part is confusing, that''s true. There are
only three comma''s in the argument list of the first version of
ugly. The syntax of C++ allows you to skip the comma''s when
no actual arguments follow. Comma''s before an override are
significant, of course.

There is a possible ambiguity looming, but it might get cornered
by syntax like this:

ugly(int,bool,char,"Farewell");

-X


这篇关于空论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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