Jeffrey Baker wrote:
I am hobbyist and I am not in the enviroment of work stress and
deadlines. I
know pointers are the biggest flaw in C++ and any language. This is
where
most of the issues are. I came to know that any class in C++ that
creates a
pointer (programmer) should follow the pattern of a destructor that
deletes
the pointer of the class. This prevents a portion of 1-5 above. I would
like
to know where the exceptions to using the class destructor to delete
pointers are..
No that is not true. There are two major uses of pointers. The first is
about ownership, the pointer is a handle for some dynamic resource that
must be released in a timely fashion. This ownership should be unique
and, if necessary passed on to another pointer. An example of this kind
of use is auto_ptr which was designed to handle the semantics of
ownership. Yes there are other smart pointers that support the same
semantics.
The second use is to provide a relationship between two otherwise
independent items. Many pointers of this type can exist concurrently as
long as nothing removes the object they point to.
The latter use of pointers is much more common in C, but still has its
uses in C++. Whether I use a raw pointer or some kind of smart pointer
for this usage depends on whether I need to worry about the object being
destroyed.
Yes, I agree. The practial side is whether we use a smart pointer or the