After owning "Thinking in C++" by Bruce Eckel, for many years I opened it to look at some reasoning behind iostreams. On page 200, there is a chapter heading "why iostreams?".
The first couple of sentences are as follows:
"You may wonder whats wrong with the good old C library. And why not "wrap" the C library in a class and be done with it?"
Well, I think that this is very interesting but I am not a senior enough programmer (actually I'm an EE) to understand libraries and classes at the highest level. I have been searching on line for information as to "why would one want to "wrap a library in a class" or as I would put it; at what point is a library more efficiently implemented as a class?
Can anyone please give me a link to some information on this topic?
C doesn't have classes. C++ programmers prefer classes and all the advantages that comes with them. Instead of rewriting the whole library to fit better with C++ idioms they can reuse the C library and just put it inside classes.
Thank you Peter, for your response. I don't suppose that you could point to a simplistic example of where this has been done? Seems like something that would be beneficial to learn for a c++ programmer.
at what point is a library more efficiently implemented as a class?
Efficiency isn't the issue here. If you have an object with some well (or not so well) defined behavior, it is natural to give it a distinct type, to make it easier to reason about the program, to define interfaces and interactions.
The C I/O library operates on streams, stream buffers, and the locale (multiple locales in most implementations, but the standard only requires one at a time). These objects are all managed by the C runtime, which exposes a mishmash of functions, preprocessor macros, and opaque implementation-defined types to the programmer.
And then there is GTKmm for C++. It has a class called Gtk::Image. Take a look at the member functions: http://developer.gnome.org/gtkmm/stable/classGtk_1_1Image.html
As you see many of the member functions have similar names to the functions in GTK+.