为什么我们需要课程 [英] Why we need classes

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

问题描述

我是一个新人加入了你PLZ尝试帮助我bcoz我不能

找到这个问题的可疑答案

Qus>>为什么呢当结构提供类似的

功能时,我们需要类吗?

I am a new one who have joined u plz try to help me bcoz i could not
find ny sutiable answer foer this Question
Qus>>why do we need classes when structures provide similar
functionality??

推荐答案

结构默认是公共的和类默认情况下是私有的。

除非您使用私有,公共或受保护的关键字,否则结构中的任何成员

功能或成员数据都将是公开的。

封装背后的想法是隐藏细节,需要私有

数据并提供该类用户的公共接口方法

可以使用。

structures are public by default and classes are private by default.
Unless you use the keywords private, public or protected, any member
funtions or member data in a structure will be public. The idea behind
encapsulation is to hide the details, it is desireable to make private
data and provide public interface methods that the user of the class
can use.


2005年2月27日19:34:41 -0800,Pratts < it ********* @ rediffmail.com>

在comp.lang.c ++中写道:
On 27 Feb 2005 19:34:41 -0800, "Pratts" <it*********@rediffmail.com>
wrote in comp.lang.c++:
我是一个新的谁加入了你PLZ试图帮助我bcoz我无法找到这个问题的可疑答案
Qus>>为什么我们需要课程,当结构提供类似的功能??
I am a new one who have joined u plz try to help me bcoz i could not
find ny sutiable answer foer this Question
Qus>>why do we need classes when structures provide similar
functionality??




提出这个问题的一个更好的方法是:


"为什么我们在上课时需要C ++中的结构?


默认访问存在差异,但这非常简单。


为了向后兼容C代码需要结构,其中

存在数百万行,因为C ++应运而生。

类只不过是一种文档机制。


-

Jack Klein

主页: http://JK-Technology.Com



comp.lang.c http://www.eskimo.com/~scs/C- faq / top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu .edu / ~a ... FAQ-acllc.html



A better way to ask this question would be:

"Why do we need structs in C++ when we have classes?"

There is a difference in default access, but this is really trivial.

Structs are needed for backwards compatibility with C code, of which
there were millions of lines in existence as C++ came into being.
Classes are little more than a documentation mechanism.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


" Pratts"写道:
"Pratts" writes:
我是一个新人加入你的PLZ尝试帮助我bcoz我无法找到这个问题的可疑答案
Qus>> ;当结构提供类似的功能时,为什么我们需要类?
I am a new one who have joined u plz try to help me bcoz i could not
find ny sutiable answer foer this Question
Qus>>why do we need classes when structures provide similar
functionality??




如果你的意思是为什么我们需要关键字class除了stuct,

答案是,我们不是。这只是为了方便而且,正如通常使用的那样,

改进了文档。



If you mean why do we need the keyword "class" in addition to stuct, the
answer is, we don''t. It''s just for convenience and, as typically used,
improves documentation.


这篇关于为什么我们需要课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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