ni*****@gmail.com wrote:
I would like to know more about C++ wrappers. What is a wrapper object
in C++ and why is it neccessary? I am trying to create a templated
linked list data structure to store any object or primitive however I'm
told it would work best with a wrapper object. I did a google search
and came up with a java
definition(http://javaalmanac.com/egs/java.lang/Wrap.html) would it
work for C++ the same way?
A wrapper object most likely would act on behalf of the object in wraps,
in a way that would make accessing the wrapped object:
possible (e.g. if the wrapped object is somewhere on the Internet);
easier (e.g. if the wrapped object has a crumblesome interface);
safer (e.g. keeps locks, reference counting, etc);
faster (by utilizing optimized operation, by caching last result, etc);
recordable (bookkeeping debug information, records exception, etc);
abstract (by doing away some unnecessary operations and so make it
compliant to other similar objects);
more flexible (e.g. the damage done by changing the public interface of
the wrapped object is contained);
more managible (e.g. if the wrapper does give a simpler interface, etc.)
There are also cases when a wrapper object wraps around an interface
that does not explicitly use C++ class objects. These wrappers
simplifies, encapsulates, restructures, refactors and in some cases
adapts the wrapped interface to suit your needs.
Ben