struct vs class
so i've learned to program through JAVA and C++ in school. I use classes like I breath air. But, I've yet to ever use a struct.
Recently, to my surprise, I ran into a bunch of structs that included functions. I didn't know structs could have methods (behavior)! I thought they could only have data(state). I understand the idea of having a struct include function pointers, so my question is:
if structs can have methods, what are the primary differences between structs and classes in C++?
Quote:Original post by datadawgx
primary differences between structs and classes in C++?
absolutely none, structs defaults to public access and public inheritance while classes defaults to private access and private inheritance.
structs are, I believe, a throwback to C and are kept around for backwards compatability.
The only time I use a struct is when I simply need a container of related values but no methods.. though a public class would be exactly the same.
The only time I use a struct is when I simply need a container of related values but no methods.. though a public class would be exactly the same.
Quote:Original post by pragma Fury
structs are, I believe, a throwback to C and are kept around for backwards compatability.
The only time I use a struct is when I simply need a container of related values but no methods.. though a public class would be exactly the same.
yeah, I do that, but I end up defining action methods, and it ends up being a serial data access class :P
Quote:Original post by SarumanIf you're using a Microsoft platform, consider using the __interface keyword rather than struct/class, as that gives you some help during compilation. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/key_f-r_3.asp
I use structs as interfaces :)
Quote:Original post by snk_kidhe says, and goes on to describe the differencesQuote:Original post by datadawgx
primary differences between structs and classes in C++?
absolutely none
Quote:Original post by Anonymous PosterQuote:Original post by snk_kidhe says, and goes on to describe the differencesQuote:Original post by datadawgx
primary differences between structs and classes in C++?
absolutely none
It was clear that he was pointing out that they have none of the larger differences the OP had in mind.
Quote:Original post by Anonymous PosterQuote:Original post by snk_kidhe says, and goes on to describe the differencesQuote:Original post by datadawgx
primary differences between structs and classes in C++?
absolutely none
[headshake] That does not change the fact there is no difference as you can just specify not to do the default and you can do the same stuff in both.
Also not matter how people use structs the only C++ types compatible with C are POD-types, classes can just as easily be POD-types as can structs just as easily be NON POD-types.
Quote:Original post by Anonymous PosterQuote:Original post by snk_kidhe says, and goes on to describe the differencesQuote:Original post by datadawgx
primary differences between structs and classes in C++?
absolutely none
Quote:Original post by Anonymous PosterQuote:Original post by SarumanIf you're using a Microsoft platform, consider using the __interface keyword rather than struct/class, as that gives you some help during compilation. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/key_f-r_3.asp
I use structs as interfaces :)
Please note that these posts were made by different APs ;)
Best Regards,
//AP1
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement