0

Is there a difference between a class and a struct? At first I thought a struct could not have methods/constructors/destructors, but now I found out they can, so what is the difference?

4
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by sarehu
0

The Complete Reference C++ (4 ed) goes into pretty good detail about the relationship between a class and a struct. Basically, the struct is part of the C subset of C++ and was kept in the language (with some enhancements) so that C++ would always be compatible with C. The book also warns that, although you can do a lot with struct, it should be reserved for when you need to create a C-style structure [no data members, no constructors/destructors].

0

So, in C++ they made a WHOLE other, um, (I want to say structure, but that would be confusing), thing that's the exact same as a struct, which they could have kept, but they made a whole new one, just to make the default access level private?

0

Yep. It might have been the case that the guy who designed C++ at first thought that only classes would have member functions, but then gave structs the ability too for some reason or another.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.