c++ struct

D

dis_is_eagle

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
 
H

hankssong

the c++'s struct in the default case, member variables and functions
are public where in c++'s class are private.
just code a test example to test your assumption,
it is quite easy.
or googling,you will get enough info.

(e-mail address removed) 写é“:
 
K

Keith Thompson

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.

What is this "C++" of which you speak?

If it's some other programming language, perhaps they discuss it in
comp.lang.c++. Perhaps that newsgroup even has its own FAQ. Perhaps
your question is answered somewhere around section 7, say question 7.8
or so. Or perhaps not. We have no idea; we only discuss C here.
 
M

Malcolm

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
A C struct consists of the declaration

struct <structname>
{
<a least one member type : name>
};

There are also special rules for bitfields.

C++ structs are similar, but member functions are allowed. As for the
details of inheritance, I've genuinely forgotten; it's years since I used
C++ and even more since I used a C++ struct with function members.
 
A

Aman JIANG

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.

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)

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.)
 
D

Dave Thompson

<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.)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top