The Microsoft Foundation classes provide many diagnostic features, but diagnostic object printing and validity checking are specific services of the CObject class. For diagnostic features that are not class oriented, see “Memory Diagnostics” later in this chapter, on page 29.
The CDumpContext class works in conjunction with the Dump member function of the CObject class to provide formatted diagnostic printing of internal object data. CDumpContext, like the ostream class (in the iostream library), provides an insertion (<<) operator that accepts not only CObject pointers but also standard types and CString and CTime objects.
A predefined CDumpContext object, afxDump, is available in the Debug version of the Microsoft Foundation classes (#define _DEBUG is required in your source code). With MS-DOS, the output from afxDump goes to stderr. With Windows, the output goes to the CodeViewÒ debugger if it is present; otherwise it goes to device AUX.
Without any programming on your part, the Dump member function of the CObject class provides a hexadecimal printout of the contents of your derived object. If you override the base class Dump member function in your derived class, you can get a formatted dump of your object's contents. If you have used the DECLARE_DYNAMIC or DECLARE_SERIAL macros in your derived class declaration and if you have used the IMPLEMENT_DYNAMIC or IMPLEMENT_SERIAL macros in your derived class implementation, then Dump prints your object's class name even if you supply a generic CObject pointer.
The AssertValid member function of CObject always returns TRUE. If you override the base class AssertValid member function in your derived class, you can perform a specific test of your object's internal consistency.