struct vs class

Apr 5, 2010 at 6:54am
can anyone tell me the difference between a struct and a class? they seem very similar to me. also what are the benefits of using one over the other? i usually use classes but will use structs more if i know how it useful for me.
Apr 5, 2010 at 6:57am
The only difference between a class and a struct is the default access modifier.
Check this out -> http://www.cplusplus.com/forum/beginner/21863/
Last edited on Apr 5, 2010 at 6:59am
Apr 5, 2010 at 10:14am
I personally use a struct when I know all members would be public. But you can use a class always anyway.
Apr 5, 2010 at 10:23am
Struct is from C. C++ has it to be compatible with C but in C++ behaves almost the same as a class
Apr 5, 2010 at 3:46pm
i see....not really a big diff huh, thanks alot guys. but is one more efficient than the other? like is more memory allocated to make a class than a struct? or is the only diff really the default access modifier?
Apr 5, 2010 at 3:59pm
The only difference is the default access of members / inheritance
Apr 5, 2010 at 4:07pm
closed account (S6k9GNh0)
Seriously, in the definition of the C++ language, that is exactly what it says. One is no more efficient than the other at any time or place.
Topic archived. No new replies allowed.