两个问题求助! [英] Two questions for help!

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

问题描述

1。在一本书中显示,一个类具有声明为

protected的所有成员变量。这样做的原因是什么?


2.未命名的命名空间和全局范围,它们是否相同?


谢谢为了你的帮助!

1. It is showed in a book that a class has all member variables declared as
protected. What''s the reason for doing this?

2. Unnamed namespace and global scope, are they equivalent to each other?

Thanks for your help!

推荐答案

" away" <谷******* @ spambs.com>写道:
"away" <Gu*******@spambs.com> wrote:
1.在一本书中显示一个类将所有成员变量声明为
protected。这样做的原因是什么?


使变量受保护确保只有类和子类

才能修改变量。假设子类编写者将会非常小心。


就个人而言,我觉得所有变量都应该被声明为私有。

2.未命名的命名空间和全局范围,它们是否相互等同?
1. It is showed in a book that a class has all member variables declared as
protected. What''s the reason for doing this?
Making a variable protected ensures that only the class and sub-classes
can modify the variable. The assumption is that sub-class writers will
be careful enough.

Personally, I feel that all variables should be declared private.
2. Unnamed namespace and global scope, are they equivalent to each other?




编号在未命名的命名空间中声明的变量只能被访问

来自包含它的cpp文件。全局范围内的变量可以从程序中的任何位置访问。



No. A variable declared in an unnamed namespace can only be accessed
from the cpp file that contains it. A variable in global scope can be
accessed from anywhere in the program.




" away" <谷******* @ spambs.com>在消息中写道

news:rv ********************* @ bgtnsc05-news.ops.worldnet.att.net ...

"away" <Gu*******@spambs.com> wrote in message
news:rv*********************@bgtnsc05-news.ops.worldnet.att.net...
1.在书中显示,一个类将所有成员变量声明为
作为受保护。这样做的原因是什么?


因此派生类可以访问这些成员。

这是一个设计决定,取决于性质

of问题正在解决。

2.未命名的命名空间和全局范围,它们是否相同?
1. It is showed in a book that a class has all member variables declared as protected. What''s the reason for doing this?
So that derived classes may have access to those members.
This is a design decision that depends upon the nature
of the problem being solved.

2. Unnamed namespace and global scope, are they equivalent to each other?




No.


-Mike



No.

-Mike


Daniel T.写道:
Daniel T. wrote:
2.未命名的命名空间和全局范围,它们是否相当于每个
2. Unnamed namespace and global scope, are they equivalent to each


其他?


这些来自测试吗?

否在未命名的命名空间中声明的变量只能从包含它的cpp文件中访问。可以从程序中的任何位置访问全局范围内的变量。

other?

Are these from a test?
No. A variable declared in an unnamed namespace can only be accessed
from the cpp file that contains it. A variable in global scope can be
accessed from anywhere in the program.



未命名的命名空间的更好名称是名称<的命名空间 br />
不能写。否则,未命名的命名空间对于

每个翻译单元都不是唯一的;全球一个未命名。


-

Phlip
http://industrialxp.org/community/bi...UserInterfaces



A better name for the unnamed namespace would be "the namespace whose name
cannot be written". Otherwise the unnamed namespace would not be unique to
each translation unit; the global one would be unnamed.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


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

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