FAQ 26.05 What are zombie objects (and why should they be avoided)?

Zombie objects are C++'s version of the living dead objects that aren't quite alive but aren't quite dead either.

When an environment doesn't support throw or when a programmer decides to avoid throwing exceptions from constructors (see FAQ 26.04), an object that can't finish its constructor can set an internal status flag to indicate that the object is unusable. Then the class provides a query (inspector) member function so that users can see whether the object is usable or a zombie.

The zombie object technique has the unfortunate side effect of allowing objects to survive even though their constructor failed. This means that all member functions must first check to make sure the object isn't a zombie before using the data inside the object and that all users of an object must check to make sure the object is usable after creating the object.

In general, the zombie technique is inferior to throwing an exception.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net