Re: C/C++ question about dynamic "static struct"
Les Cargill <lcargill99@comcast.com> wrote:
When you
don't need a lot of dynamic behavior, something like 'C' seems
to fit better.
There seems to be a really common misconception among many C advocates
that the only thing that the additional features offered by C++ are good
for is for managing dynamically allocated memory. This couldn't be farther
from the truth.
RAII is useful for things other than managing memory. For example, it can
be used to more easily close file handles and release mutex locks, making
the code simpler, safer and less error-prone, requiring less coding
conventions that exist solely to avoid those errors.
The very support for classes is in itself a big advantage over the raw
structs of C, even if you don't make any dynamic memory allocation at all.
It makes it easier to design your program modularly, to have compile-time
checks, and to make syntax simpler. Inheritance can also be useful even
when you don't need dynamic memory allocation.
Templates are a big one. Not only do they make many things simpler, they
can also make them more efficient. (For example, just compare the speed
of std::sort() compared to qsort(). The speed advantage of the former
comes thanks to the fact that it's a template function. Also, the former
is much easier to use than the latter.) And that's only scratching the
surface.