struct vs class
kaseron (106)
Aug 27, 2012 at 11:13pm UTC
I am writing a sudoku-type game, and I want to have a random generator call a game from a list of saved games. Should I use a struct, a class, or something else?
Peter87 (3912)
Aug 27, 2012 at 11:21pm UTC
struct and class is the same thing. Only difference is that with class the default is private and with struct the default is public.
Dash (122)
Aug 27, 2012 at 11:22pm UTC
The only difference between a struct and a class , is the default access level. A struct 's default access level is public , while the latter's is private .
kaseron (106)
Aug 27, 2012 at 11:30pm UTC
In that case, I will use a struct.
Thanks for responding!
georgep (158)
Aug 28, 2012 at 1:25am UTC
I thought that struct couldn't have member functions?
PanGalactic (1581)
Aug 28, 2012 at 1:38am UTC
georgep wrote:I thought that struct couldn't have member functions?
Try it and see.
Really -- the only two differences are default member access and inheritance type (public/private).
georgep (158)
Aug 28, 2012 at 1:51am UTC
Huh, I never knew that!
I thought structs were a C thing and classes were a C++ thing. Are there really other differences between them?
I'm guessing you can't use inheritance with structs, but I'm probably wrong there too.
Disch (8615)
Aug 28, 2012 at 2:38am UTC
I'm guessing you can't use inheritance with structs, but I'm probably wrong there too
You can.
As PanGalactic said... the only difference is the default access.
That said... structs and classes are conceptually different, even if the language doesn't treat them very different.
Topic archived. No new replies allowed.