[cs13001] Advantages of classes over structures.
Mikhail Nesterenko
mikhail at cs.kent.edu
Sun Dec 9 22:46:33 EST 2012
>
> Hey Pr.Nesterenko,
>
> Was reading on the internet, but couldn't find a reasonable
> explanation of advantages of classes over structures (most sites
> said they both are pretty much the same with the exception of the
> private and public in classes.
>
> So I was hoping you could tell me, what are the main advantages of
> classes over structures?
>
Well, structures is a construct inherited from C, while classes is one
of the major constructs that was introduced in C++ which effectively
made the language object-oriented. Originally, structures only had
member variables and functions (methods) cannot be defined for them.
However, as C++ evolved, structures got all the features that were
introduced for classes first and, except for minor differences, they
are equivalent. In modern C++, there is no reason to use structures
instead of classes. In this course we studied structures as a stepping
stone to study classes.
If there is a question of comparing classes and structures on the
exam, I would like you to emphasize that classes is a construct that
aggregates the data (attributes) and code (methods) and thus makes the
program more modular and easy to develop and maintain (even though
technically structures in modern C++ can do that as well).
Thanks,
--
Mikhail
More information about the cs13001
mailing list