The one and only difference is that, if you have a member declared before you use public, private, or protected, it defaults to public in a struct and private in a class.
Otherwise, there's absolutely no functional difference between a struct and a class.
Typically, you use a struct when you have something that's intended to be POD (plain-old data) or to clearly indicate that all its members are public (or even that it has no members). You could just as easily use a class and just declare everything public, but using struct is often clearer and requires less typing.
struct
{
int a,b,c;
constructor
destructor
functions
};
class
{
constructor
destructor
functions
...
int a,b,c;
}
sizeof(struct) will be the sizeof the datamembers but the sizeof(class) may not. Useful when you want to dump the struct to a file and read it back in (in the no class or pointer situtation).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.