struct和class之间的区别 [英] Difference between struct and class
问题描述
我们讨论了一个类和一个结构之间的差异,
并且没有人达成一致。据我了解,结构默认为
public,类默认为private。有关施工人员的问题
我不清楚。我知道我可以用一个带有构造函数,析构函数,访问器和修饰符的
类来完成一个简单的项目,将类更改为结构类,并编译它运行正常。可以某种灵魂
勾勒出差异,还是指向一个这样做的来源? TIA :)
OOK写道:我们已经对类和结构之间的区别的讨论,
并没有人同意。据我了解,结构默认为public,类默认为private。关于施工人员的问题我不清楚。我知道我可以使用一个带有构造函数,析构函数,访问器和修饰符的类的简单项目,将类更改为结构体,并且它可以编译并运行良好。某种善良的灵魂可以概述这些差异,还是指向一个有这种差异的来源? TIA:)
请参阅此常见问题解答:
http://www.parashift.com/c++-faq-lit...s.html#faq-7.8
干杯! --M
Ook写道:我们讨论了一个类和一个结构之间的差异,
IAW C ++标准唯一的区别是默认的公共VS默认值
private。
那个是吗。没有别的。
但是,一些程序员使用一般规则,他们使用struct
用于POD类型和类用于复杂类型。
但这与官方C ++标准无关。
请参阅此常见问题解答:
http://www.parashift.com/c++-faq-lit...s.html#faq-7.8
干杯! --M
因此,默认构造函数等方面没有区别吗?我依旧记得与施工人员有关的事情,我会看看是否能找到
我的讲义,所以我知道要问什么问题:P
We have had a discussion on the differences between a class and a structure,
and no one is in agreement. As I understand it, a structure defaults to
public, a class defaults to private. There are issues about constructors
that I''m not clear on. I do know that I can take a simple project with a
class that has constuctors, destructors, accessors, and modifiers, change
the classes to structs, and it compiles and runs fine. Can some kind soul
outline the differences, or point me to a source that does so? TIA :)解决方案Ook wrote:We have had a discussion on the differences between a class and a structure,
and no one is in agreement. As I understand it, a structure defaults to
public, a class defaults to private. There are issues about constructors
that I''m not clear on. I do know that I can take a simple project with a
class that has constuctors, destructors, accessors, and modifiers, change
the classes to structs, and it compiles and runs fine. Can some kind soul
outline the differences, or point me to a source that does so? TIA :)
See this FAQ:
http://www.parashift.com/c++-faq-lit...s.html#faq-7.8
Cheers! --M
Ook wrote:We have had a discussion on the differences between a class and a structure,
and no one is in agreement. As I understand it, a structure defaults to
public, a class defaults to private. There are issues about constructors
that I''m not clear on. I do know that I can take a simple project with a
class that has constuctors, destructors, accessors, and modifiers, change
the classes to structs, and it compiles and runs fine. Can some kind soul
outline the differences, or point me to a source that does so? TIA :)
IAW C++ standard the only difference is the default public VS default
private.
That is it. Nothing else.
However, some programmers user a general rule in which they use struct
for POD types and class for complex types.
But that has nothing to do with the official C++ standard.
See this FAQ:
http://www.parashift.com/c++-faq-lit...s.html#faq-7.8
Cheers! --M
So there are no difrerences with respect to default constructors, etc.? I
vaguely remember something related to constructors, I''ll see if I can find
my lecture notes so I know what question to ask :P
这篇关于struct和class之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!