By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

what is difference between structure and class?

P: 1
structure in c and class in c++
Dec 19 '10 #1
Share this Question
Share on Google+
2 Replies

P: 14
Structures can not have functions in them.
Classes have the ADDED functionality of being able to have functions
Dec 19 '10 #2

Expert Mod 5K+
P: 9,197
There is only one difference between a struct and a class: The default access for struct members is public whereas the default access for class members is private.

C++ comes from C and in C there is only one way to group data members together: a struct. Therefore, C++ has only structs.

A class is a term used in object technology to represent a group of data members managed by operations.

To make C++ look more object-like a "class" was added to the language. It is implemented as a struct with a private default access.

That means C++ structs can have constructors, destructors, etc.

Try it out. Write a class and get it working with a constructor, destructor and maybe another member function. Once it works, change the "class" keyword to "struct" and rebuild. You will see abolutely nothing happen. The code will work as before.
Dec 19 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.