I've always thought about how other programmers use classes or struct if they want to define their own type, provided they explicitly (not implicitly) make members public or private. I'd prefer to use classes if I'm using public member function with private variables, and just leave struct only for public variables.
Thoughts?
EDIT:: accidentally left "cl_one" declared as a struct, instead of a class.
If its for somthing quite simple, i.e. a few variables, I would use a struct, otherwise I would use a class if it has functions etc. If you have a function to call and you find you are passing say 6 arguments I would replace that with a struct, then you needn't change the function signature but only the struct. It's all down to a matter of taste. I also like to keep my code looking good, if your code starts looking messy somthing is wrong somwhere, but I am now digressing...
The only difference between struct and class to a compiler is that by default, without you stating so, struct members are public, whilst class members are private:
1 2 3 4 5 6 7 8 9
struct my_struct
{
int member; //this is public
};
class my_class
{
int member; //this is private
};
Other than that, they are the same. Structs are a C-feature and in C you are not allowed to define member functions as in C++. So I like to use structs for simple type which only have data members. The only member functions I might define are overloaded operators, if applicable.
However I am used to use "struct" only when the the usage of "struct" would be also legal in C. So I usually use the keyword "struct" to identify a simple data structure (all public variables, no functions).... except some very rare situations where I decide to make an exception.
In the other cases I prefer to use the keyword "class".
It is my own personal style.... but, like NwN said, in C++ there is no an actual difference from "struct" and "class" (a part the difference of "public as default" vs "private as default") so you are absoultely free to use one keyword or another indifferently
Unless I am required to by a style guide, I never use the keyword "class". It's just personal preference (I like being rebellious by using "struct" for high-level C++ classes). So really you can do whatever you want.
I recommend sticking to one style though - decide when you will use class or struct to define a class and stick to that definition unless a group or work project requires otherwise.