C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 309,245 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,636 people online right now. Registration is fast and FREE... Join Now!




Struct vs Class

 

Struct vs Class, Difference between class and struct in C++

mono15591

16 Sep, 2009 - 10:07 AM
Post #1

D.I.C Regular
***

Joined: 5 Nov, 2008
Posts: 356



Thanked: 11 times
My Contributions
I haven't read any real difference between struct and class in C++
A class has a constructor and destructor and all things are private by default
A struct doesn't have a constructor or destructor and are public by default
Other than these differences they are exactly the same am I wrong?

Is one a better choice over the other in certain situations?

This post has been edited by NickDMax: 16 Sep, 2009 - 11:59 AM

User is offlineProfile CardPM
+Quote Post


Posts in this topic
mono15591   Struct vs Class   16 Sep, 2009 - 10:07 AM
Neumann   A struct doesn't have a constructor or destru...   16 Sep, 2009 - 10:15 AM
deery5000   classes have many more things to them than constru...   16 Sep, 2009 - 10:18 AM
snowflakes   web search http://www.google.co.uk/#hl=en&sou...   16 Sep, 2009 - 10:18 AM
carltech   I like to consider structs more like a custom data...   16 Sep, 2009 - 10:31 AM
NickDMax   You know we just covered this a couple of pages ba...   16 Sep, 2009 - 11:17 AM
Neumann   The only thing that is different is that structs ...   16 Sep, 2009 - 11:23 AM
Pwn   I use structs quite often when I just want to gro...   27 Sep, 2009 - 04:10 AM
NickDMax   You know I am wrong... a struct CAN have private m...   16 Sep, 2009 - 11:41 AM
NickDMax   Stroustrup goes on to say: This was basically my ...   16 Sep, 2009 - 11:56 AM
KYA   This seems to me to be an example of "you can...   16 Sep, 2009 - 11:57 AM
Aeternalis   What about inheritance? Can inherit from a struct?...   16 Sep, 2009 - 02:30 PM
NickDMax   I have actually see struct inheritance used though...   16 Sep, 2009 - 02:35 PM
Aeternalis   yeah.. I was thinking of C structs which do not su...   16 Sep, 2009 - 02:42 PM
Bench   According to the standard, The one and only differ...   16 Sep, 2009 - 03:13 PM
mono15591   My topic got featured :D Yay! Sorry for the ...   17 Sep, 2009 - 05:08 AM
poncho4all   I was jumping around and i found this turorial on ...   17 Sep, 2009 - 04:40 PM
carltech   Yes, but it is not the most usual practice...or at...   17 Sep, 2009 - 04:56 PM
poncho4all   Ok i found some examples on the struct with functi...   17 Sep, 2009 - 05:09 PM
KYA   I feel like we're beating the dead dog here a ...   17 Sep, 2009 - 05:13 PM
NickDMax   structs can do EVERYTHING that classes can do. So ...   17 Sep, 2009 - 06:48 PM
nirvanarupali   There is a differece between a C-struct and a C++...   20 Sep, 2009 - 06:36 PM
Neumann   I think some people have a hard time understanding...   17 Sep, 2009 - 06:51 PM
NickDMax   @poncho4all -- BTW the quotes I gave here and here...   17 Sep, 2009 - 06:58 PM
onecsguy   It is interesting to note that in C# and I think j...   18 Sep, 2009 - 05:22 AM
smacdav   It is interesting to note that in C# and I think ...   18 Sep, 2009 - 10:45 AM
AdamSpeight2008   In .net (vb & C#) a Structure is a value type ...   18 Sep, 2009 - 12:44 PM
Oler1s   The value/reference concept you speak of does not ...   18 Sep, 2009 - 12:50 PM
Plus   there is a difference normal programmers don't...   18 Sep, 2009 - 08:15 PM
Plus   in C case it will be this struct A { int a; ...   18 Sep, 2009 - 09:51 PM
netGhost   mhmmm I don't quite understand the difference ...   18 Sep, 2009 - 10:19 PM
KYA   Plus, C++ doesn't have closures.   19 Sep, 2009 - 08:15 AM
poncho4all   Just for closure and to check if i understood. Cla...   21 Sep, 2009 - 03:00 PM
NickDMax   ..well... unions are a horse of a different color....   21 Sep, 2009 - 10:08 PM
Plus   people who designed C++ has made a rule for struct...   22 Sep, 2009 - 07:56 PM
NickDMax   This is actually not true. Structures might be m...   22 Sep, 2009 - 09:02 PM
Pwn   The compiler pads the data to make the elements...   27 Sep, 2009 - 04:23 AM
NickDMax   ...well one might use a pair... but lets take a lo...   27 Sep, 2009 - 06:14 AM
bnolsen   Not so much difference except for the public vs pr...   20 Nov, 2009 - 08:11 PM
Hyper_Eye   This reminds me of something I run into fairly oft...   21 Nov, 2009 - 09:41 AM

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 09:40AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month