Stroustrup:第4章 [英] Stroustrup: chapter 4

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

问题描述

我有2个问题:


1.)在他使用的第4.2节中:


bool is_open(文件*)


i想知道他为什么使用指针而不是这两个:


bool is_open(File)或bool is_open(File&)

2.)第4.9节,Stroustrup说:


double sqrt(double);

enum Beer {Carlsberg,Tuborg,Thor};

命名空间NS {int a; }

这些只是声明,根据我的观点,但是Stroustrup

说这些都是定义。怎么样?


谢谢

i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)
2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?

thanks

推荐答案

arnuld写道:
arnuld wrote:

i有2个问题:


1.)在他使用的4.2节中:


bool is_open(文件*)


i想知道他为什么使用指针,而不是这两个:


bool is_open(文件)或bool is_open(文件& ;)
i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)



关键是你可以使用bool来表示逻辑结果。是否应该通过值,引用或指针传递

参数是

作者的自由。

The point is you can use a bool to indicate logical result. Whether the
parameter should be passed by value, reference or pointer is the
author''s freedom.


>


2.)第4.9节,Stroustrup说:


double sqrt(double);

enum Beer {Carlsberg,Tuborg,Thor};

namespace NS {int a; }


这些只是声明,根据我的观点,但是Stroustrup

说这些是定义。怎么样 ?
>

2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?



具体文字引用如下:


上述声明只有


double sqrt(double);

extern int error_number;

struct User;


也不是定义; ..

很明显,作者并不认为它们是定义。是什么让

你认为作者另有说法?

The exact text is quoted below:

Of the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions;...
So clearly the author does NOT regard them as definitions. What makes
you think the author says otherwise?


>

谢谢
>
thanks



欢迎


Ben

Welcome

Ben


3月4日,10:17 am,benben< benhonghatgmaildotcom @nospamwrote:
On Mar 4, 10:17 am, benben <benhonghatgmaildotcom@nospamwrote:

arnuld写道:
arnuld wrote:


bool is_open(文件)或bool is_open(文件&)
bool is_open(File) or bool is_open(File&)



重点是你可以使用bool来表示逻辑结果。是否应该通过值,引用或指针传递

参数是

作者的自由。


The point is you can use a bool to indicate logical result. Whether the
parameter should be passed by value, reference or pointer is the
author''s freedom.



好​​的,好的。顺便说一句,作为C ++的新手,我觉得,Stroustrup总是让b / b
复杂化。

ok, fine. BTW, as a newbie to C++, i feel, Stroustrup always
complicates things.


double sqrt(double);

enum Beer {Carlsberg,Tuborg,Thor};

namespace NS {int a; }
double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }


这些只是声明,根据我的观点,但是Stroustrup

说这些是定义。怎么样 ?
these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?



具体文字如下:


上述声明只有


double sqrt(double);

extern int error_number;

struct User;


也不是定义; ..


The exact text is quoted below:

Of the declarations above, only

double sqrt(double);
extern int error_number;
struct User;

are not also definitions;...



你写的最后3个是*唯一的*是声明

没有定义。 Stroustrup说,发布的三个声明* i *

是带有定义的声明。对我来说,他们看起来像是没有定义的声明。


i想要知道为什么我发布的3个声明是声明与

defintions"?

the last 3 you wrote, are the *only* ones that are "declarations
without definitions". Stroustrup says the three declarations *i*
posted are "declarations with definitions" and to me they look like
"declarations without definitions".

i want to know WHY the 3 declarations i posted are "declarations with
defintions"?


因此,作者显然不会将它们视为定义。是什么让你认为作者另有说法?
So clearly the author does NOT regard them as definitions. What makes
you think the author says otherwise?



这是关于你的3声明。那我的3.

that''s about your 3 declaration . what about my 3.


3月4日上午11点40分,arnuld < geek.arn ... @ gmail.comwrote:
On Mar 4, 11:40 am, "arnuld" <geek.arn...@gmail.comwrote:

i有2个问题:


1.)in section 4.2他使用:


bool is_open(文件*)

i想知道他为什么使用指针,而不是这些2:


bool is_open(文件)或bool is_open(文件&)
i have 2 problems:

1.) in section 4.2 he uses:

bool is_open(File*)

i want to know why he uses the pointer, instead of these 2:

bool is_open(File) or bool is_open(File&)



文件通常被认为具有对象语义而不是

比值语义所以你必须使用指针或

引用。然后,复制File对象将分别给出两个引用

要单独操作的文件。不是你想要的。


现在大多数人可能更喜欢参考而不是指针,因为参数不是指针任何意义都是可选的,但是这个

还取决于File对象是如何创建的 - 我没有这本书的副本

方便查看上下文。< br>

A file would normally be considered to have object semantics rather
than value semantics so you have to use either a pointer or a
reference. Copying the File object would then give two references to
the file to be manipulated separately. Not what you want.

It''s probable that most people now would prefer the reference rather
than the pointer as the argument isn''t in any sense optional, but this
also depends on how the File object is created - I don''t have a copy
of the book handy to see the context.


>

2.)第4.9节,Stroustrup说:


double sqrt(double );
enum Beer {Carlsberg,Tuborg,Thor};

namespace NS {int a; }


这些只是声明,根据我的观点,但Stroustrup

表示这些是定义。怎么样?


谢谢
>
2.) section 4.9, Stroustrup says:

double sqrt(double);
enum Beer { Carlsberg, Tuborg, Thor };
namespace NS { int a; }

these are declarations only, as per my point of view but Stroustrup
says these are definitions. how ?

thanks



我认为这几天的标准术语就是说

first(作为函数原型)是一个声明。第二个是

定义,因为它定义了枚举的成员。


最后我想你可能会说定义了名称空间

(尽管以后可以再次打开)并且声明了

整数a。我怀疑有些人会在后两个版本中使用不同的

术语。

K

I think the standard terminology these days would be to say that the
first (being a function prototype) is a declaration. The second is a
definition because it defines the members of the enum.

For the last I think you might say that the namespace is defined
(notwithstanding that it can be opened again later) and that the
integer a is declared. I suspect that some people would use different
terminology for these last two.
K


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

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