Class vs Struct
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 15
- Joined: Thu Jan 29, 2009 5:48 pm
Class vs Struct
I am currently learning the use of Classes and Structures and I just had to ask what the differences and similarities between the two are. When should classes be used and when should structures be used in a program. Can they even be compared? Remeber I am just learning C++ so if you can explain the answers in a fairly understandable way then please do so. Thanks for the help!
Re: Class vs Struct
Structs are classes with all members public by default other than that there is no difference in c++.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Class vs Struct
To expand a bit on herby's post with an example:
..Is the same as a struct with no private/public specifications and:
..Is the same as a class with no private/public specifications.
By the way, this question has been asked on these forums before. Please remember to use the search feature in the future before creating a new topic.
Thanks.
Code: Select all
class Example{
public:
int number;
};
Code: Select all
struct Example{
private:
int number;
};
By the way, this question has been asked on these forums before. Please remember to use the search feature in the future before creating a new topic.
Thanks.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: Class vs Struct
Also classes cannot be used in C, whereas structs can (although structs cannot contain any functions or private members in C)