473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c++ struct

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

Sep 10 '06 #1
5 2941
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.

di**********@yahoo.com 写道:
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
Sep 10 '06 #2
di**********@yahoo.com writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 10 '06 #3

<di**********@yahoo.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.
Sep 10 '06 #4
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.

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

Sep 10 '06 #5
<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
Sep 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
17568
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
10
3486
by: Rick Anderson | last post by:
All, I am receiving the following compilation error on LINUX (but not Solaris, HPUX, WIN32, etc): compiling osr.c LBFO.h(369): warning #64: declaration does not declare anything extern...
5
3276
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
19
2587
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; }...
16
3810
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
5
4311
by: Johs32 | last post by:
I have a struct "my_struct" and a function that as argument takes a pointer to this struct: struct my_struct{ struct my_struct *new; }; void my_func(struct my_struct *new); I have read...
7
2245
by: Alex | last post by:
If I have two struct. See below: struct s1 { int type; int (*destroy)(struct s1* p); } struct s2 { struct s1 base;
4
5052
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
4
9781
by: hugo.arregui | last post by:
Hi! I have two struts like that: struct { int num; int num2; struct b arrayOfB; } a;
4
2757
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.