C++ and the STL

From: sleeper75se (sleeper75se_at_yahoo.se)
Date: 2002-03-06 03:15:02


Dave wrote:

> I think you mean the use of the stream class and
> insertion/extractor operator aspects of C++,
> rather than STL. STL refers to the Standard
> Template Library that is used to create non-specific
> typed container classes (such as lists, vectors, etc.).

Actually the stream classes are part of the STL. I was under the same
impression as you, until a C++ guru at work told me otherwise...

...

> I think that would depend on your background and what you are
> accustomed to seeing. I still find it easier to "see" the logic
> of fopen's, fprintf's, etc. than the stream class and
> "<<" and ">>" operators. But the latter make more sense in C++
> projects.

I know what you are talking about... like you said, it is a matter of
what you are used to. I'm still working on mentally adjusting my C-
thinking in favor of C++.

For the benefit of the people on the list that are not into the
details of C++ and STL, here are some of the really big advantages
of "real C++", as opposed to "objectified C" that only uses the
object-functionality of C++:

* The catch/throw execption mechanism that makes the code so much
easier to read and debug. Compare with Java.

* Automatic allocation/deallocation of memory. Want to join two
strings? That's a one line job. Want to allocate a vector, array or
list that dynamically and automatically changes size as you insert or
remove data? Already taken care of. I believe it is possible to avoid
even risking memory leaks, at the design stage.

* STL is fast. Sure, there is more overhead here and there, but you
get a lot more flexibility.

* Many basic data structures, like hash-tables, stacks, lists and so
on are already in the STL. No need to reinvent the wheel.

* Easier to debug, because you need fewer lines of code than the
equivalent function in C.

The list can be made longer.

The downside is that there's a lot going on under the hood, that you
need to understand. C is more straightforward.

Regards,

Andreas



This archive was generated by hypermail 2.1.4 : 2002-07-27 12:28:39 BST