CObject::AssertValid

This method performs a validity check on this object by checking its internal state. In the Debug version of the library, AssertValid may assert and thus terminate the program with a message that lists the line number and filename where the assertion failed.

virtual void AssertValid( )
const; 

Remarks

When you write your own class, you should override the AssertValid function to provide diagnostic services for yourself and other users of your class. The overridden AssertValid usually calls the AssertValid function of its base class before checking data members unique to the derived class.

Because AssertValid is a const function, you are not permitted to change the object state during the test. Your own derived class AssertValid functions should not throw exceptions but rather should assert whether they detect invalid object data.

The definition of validity depends on the class of the object. As a rule, the function should perform a shallow check. That is, if an object contains pointers to other objects, it should check to see whether the pointers are not null, but it should not perform validity testing on the objects referred to by the pointers.

Example

See CObList::CObList for a listing of the CAge class used in all CObject examples.

// Example for CObject::AssertValid.
void CAge::AssertValid() const
{
    CObject::AssertValid();
    ASSERT( m_years > 0 );
    ASSERT( m_years < 105 );
}

For another example, see AfxDoForAllObjects.

Requirements

**  Windows CE versions:** 1.0 and later  
  Header file: Declared in Afx.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC