Jump to content
  • Advertisement
Sign in to follow this  
datadawgx

struct vs class

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Saruman
I use structs as interfaces :)
If 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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by snk_kid
Quote:
Original post by datadawgx
primary differences between structs and classes in C++?

absolutely none
he says, and goes on to describe the differences

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by snk_kid
Quote:
Original post by datadawgx
primary differences between structs and classes in C++?

absolutely none
he says, and goes on to describe the differences


It was clear that he was pointing out that they have none of the larger differences the OP had in mind.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by snk_kid
Quote:
Original post by datadawgx
primary differences between structs and classes in C++?

absolutely none
he says, and goes on to describe the differences


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Quote:
Original post by snk_kid
Quote:
Original post by datadawgx
primary differences between structs and classes in C++?

absolutely none
he says, and goes on to describe the differences



Quote:
Original post by Anonymous Poster
Quote:
Original post by Saruman
I use structs as interfaces :)
If 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


Please note that these posts were made by different APs ;)

Best Regards,
//AP1

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!