非会员与会员 [英] Non-member vs. Member
问题描述
亲爱的,
是否有明确的区别如何确定哪些功能是什么?b
一个班级的成员而不是
你的态度如何(一般来自你的经历...)
"如果函数改变了对象的状态,它应该是该对象的
成员。参考Accelerated C ++,A。Koenig,第159页。
Thx给大家。
" utab" <微米******** @ gmail.com>在消息中写道
新闻:11 ********************** @ i39g2000cwa.googlegr oups.com ...
"如果函数改变了对象的状态,它应该是该对象的
成员。参考Accelerated C ++,A。Koenig,第159页。
请注意应该是不是应该永远是。它
的意思是让它成为会员,除非你有充分的理由不这样做。
一个这样的原因可能是一个改变了两个或更多的状态
不同类的对象。这样的功能不可能是两个对象的成员。此外,这些功能并不罕见:运营商>>
可能是最广泛使用的例子。
所以有时候不可能让状态改变函数成员
他们的对象。当有选择时,这样做很好。
utab写道:亲爱的,
是否有明确的区别如何决定哪些职能成为一个班级的成员而哪些不是
这不是'' ta C ++问题....
你的态度如何(从你的经历中得出的一般方式......)
如果函数改变了对象的状态,它应该是该对象的成员。参考Accelerated C ++,A。Koenig,第159页。
我确定这里有一些例子,但是在
中
一般我同意。
文章< Me ****************** @ bgtnsc04-news.ops.worldnet.att.net>,
" Andrew Koenig" < ar*@acm.org>写道:
" utab" <微米******** @ gmail.com>在消息中写道
新闻:11 ********************** @ i39g2000cwa.googlegr oups.com ......
如果函数改变了对象的状态,它应该是该对象的
成员。参考Accelerated C ++,A。Koenig,第159页。
请注意应该是。不是应该永远是。它意味着除非你有充分的理由否则要成为会员。
一个这样的原因可能是一个改变两个或更多状态的功能>不同类的对象。这样的功能不可能是两个对象的成员。此外,这些功能并不罕见:运营商>>可能是最广泛使用的例子。
因此,有时候将状态改变函数成为其对象的成员是不可能的。当有选择时,这样做很好。
我会说,如果函数改变了
两个或多个对象,它不应该在类中,即使两个/所有
对象属于同一类型。
-
魔术取决于传统和信仰。它不欢迎观察,
也不会通过实验获利。另一方面,科学的经验基于
;它可以通过观察和实验进行校正。
Dear all,
Is there a clear distinction how to decide which functions to be
members of a class and which not
How is your attitude (Your general way from your experiences ...)
"If the function changes the state of the object, it ought to be a
member of that object." Reference Accelerated C++, A. Koenig, page 159.
Thx to you all.
"utab" <um********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
"If the function changes the state of the object, it ought to be a
member of that object." Reference Accelerated C++, A. Koenig, page 159.
Please note that "ought to be" is less strong than "should always be." It
means "make it a member unless you have a good reason to do otherwise."
One such reason might be a function that changes the state of two or more
objects of different classes. Such a function cannot possibly be members of
both objects. Moreover, such functions are not uncommon: operator>> is
probably the most widely used example.
So sometimes it''s impossible to make state-changing functions members of
their objects. Still, it''s nice to do so when there is a choice.
utab wrote:Dear all,
Is there a clear distinction how to decide which functions to be
members of a class and which not
This isn''t a C++ question....
How is your attitude (Your general way from your experiences ...)
"If the function changes the state of the object, it ought to be a
member of that object." Reference Accelerated C++, A. Koenig, page 159.
I''m sure there are examples where this doesn''t make since, but in
general I agree.
In article <Me******************@bgtnsc04-news.ops.worldnet.att.net>,
"Andrew Koenig" <ar*@acm.org> wrote:
"utab" <um********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com..."If the function changes the state of the object, it ought to be a
member of that object." Reference Accelerated C++, A. Koenig, page 159.
Please note that "ought to be" is less strong than "should always be." It
means "make it a member unless you have a good reason to do otherwise."
One such reason might be a function that changes the state of two or more
objects of different classes. Such a function cannot possibly be members of
both objects. Moreover, such functions are not uncommon: operator>> is
probably the most widely used example.
So sometimes it''s impossible to make state-changing functions members of
their objects. Still, it''s nice to do so when there is a choice.
I would go so far as to say that if the function changes the state of
two or more objects, it should not be in the class, even if both/all
objects are of the same type.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
这篇关于非会员与会员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!