So, there is only a very trivial difference between a struct
and a class
. And struct
was kept for backward compatibility with C, while class
was introduced because it is generally more appropriate for Object-Oriented Programming purely on the basis of vocabulary (i.e. in OOP with about "classes" of objects) and on the grounds of default access rights and inheritance (private) which is more in-line with OOP design philosophy. But, in practical terms, the difference between struct
and class
remains trivial.
What you call "structures" is what experienced programmers colloquially refer to as "POD-types" (Plain-Old-Data types). These are basically simple little bundle of data like:
struct Vector2d {
double x;
double y;
};
By convention, in C++, people use the keyword struct
when creating such simple classes, and thus, people sometimes call them "structures", but I tend to dislike this awkward, overly general wording.
So, the purpose of POD-types is similar to that of any other class, except that, in this case, you don't have any functionality to associate directly to the class (or very little functionality). In other words, when you just want to bundle a bunch of data elements together, not much more. POD-types are a special kind of "value-objects" (or value-classes).
>>How do they help with coding?
Well POD-types help with coding just because data structures are omni-present in programming tasks and very often all you need is to group a number of variables together as one logical entity, …