"news.tkdsoftware.com" <ch***@noreply.nospam.tkdsoftware.com> wrote in
message news:wc****************************@tkdsoftware.co m...
Could someone illustrate how I could implement reference counting within
my base class which all my classes are derived from so that all my objects
are reference counted. This way once I create my classes and all their
references have been released, the object is then deleted instead of me
having to keep up with whether it has 0 references or not?
The FAQ (
http://www.parashift.com/c++-faq-lite/) contains a good example of
a reference-counted pointer implementation under section 16 ("Freestore
management") questions 21 ("How do I do simple reference counting?") on. If
you inherit from the class that the FAQ calls Fred, you should be able to
use "FredPtr" for reference counting instances of the derived class, too.
Don't forget the virtual destructor, of course. Also, instead of writing
your reference counting own code, consider using something like
boost::shared_ptr.
--
David Hilsee