<OT(C++ is generally considered 'off-topic' in this group, which we
abbreviate OT. I like to use it as an HTML/XML-style tag, to set it
off from content. I consider the relationships and particularly
similarities between C++ and C close enough to discuss, but you should
be warned quite a few people here disagree with this.)
On 10 Sep 2006 10:38:31 -0700, "Aman JIANG" <Am*******@gmail.com>
wrote:
di**********@yahoo.com wrote:
Hi.I would like to know the difference between a C struct and a C++
struct.I think in a C++ struct member variables and functions are by
default private whether in a C struct they are public by default.Is
there any other differences? Does a C++ struct support inheritence like
a C++ class?Thanks for any help.
Regards,
Eric
My english is bad, by-your-leave.
Okay. The only difference between a struct and a class in _C++_ is:
By default, struct is _public_, but class is _private_;
A C++ struct support all the things as a C++ class, just different
keyword.
Right.
If that a C++ struct/class has no virtual functions, no virtual base
classes,
and has a single access section, i think it will be the same to a C
struct.
(non-virtual functions and/or static-data-members are inessential)
If it has no virtual functions, no base classes (virtual or not),
(instance) data members if any all 'public'* AND contains no
(instance) pointer-to-member or reference and has no user-defined copy
assignment or dtor, then it is 'Plain Old Data' abbreviated POD and is
layout-compatible with C. (I don't understand why those last two are
required, and I needed to recheck them in the Standard because they're
unobvious to me, but that's FAR off-topic. * 8.5.1p1 doesn't say the
declarations have to be in a single 'public:' section, but 9.2p12 (and
5.p2) may require it in order to get members in the expected order.)
But, i think, never to use a C++ struct/class as a C struct, it will
goes to
break the rules of C++. The C++ classes can do anythings that C can do.
(if you are ardent, point out my mistake on knowledge or English,
thanks.)
<OT but since you asked'ardent' is an obscure word that is nowadays
used mostly about love and lovers. You probably wanted to say 'If you
are willing' or just 'Please'. But you don't need to. About the
technical content, the accepted practice in technical newsgroups like
this one is that correction of technical mistakes or flaws is always
expected, and always done unless someone just misses it.
About English, most people here don't like to discuss it since it is
not the proper topic of the group; but those few who do like to,
including me, will probably do so without being asked. I make an
effort to never -- well, almost never -- post if the ONLY thing(s) I
have to say is(are) about English issues; but I will include them in
the same post with technical responses -- as I did here. Cheers.
- David.Thompson1 at worldnet.att.net