ASSERT_VALID

 

ASSERT_VALID( pObject )

 

一个宏,用来验证值是否不为null.

参数: pObject 指定了从CObject继承的类的对象,它具有AssertValid成员函数的重载版本。

说明:
这个函数用于检验你对对象内部状态的有效性的假定。ASSERT_VALID调用作为参数传递给它的对象的AssertValid成员函数。
在MFC的发行版本中,ASSERT_VALID什么也不做。在调试版本中,它检验一个指针是否为NULL,并且调用对象自己的AssertValid成员函数。如果这些测试中有些失败了,它就按照与ASSERT相同的方式显示一个警告信息。
注意:这个函数仅在MFC的调试版本中才有。
有关的更多信息以及示例参见《Visual C++程序员指南》中的“MFC 调试支持”。

请参阅:
ASSERT, VERIFY, CObject, CObject::AssertValid

ASSERT_VALID
ASSERT_VALID( pObject )

Parameters

pObject

Specifies an object of a class derived from CObject that has an overriding version of the AssertValid member function.

Remarks

Use to test your assumptions about the validity of an object’s internal state. ASSERT_VALID calls the AssertValid member function of the object passed as its argument.

In the Release version of MFC, ASSERT_VALID does nothing. In the Debug version, it validates the pointer, checks against NULL, and calls the object’s own AssertValid member functions. If any of these tests fails, this displays an alert message in the same manner as ASSERT.

Note This function is available only in the Debug version of MFC.

For more information and examples, seeMFC Debugging Support in Visual C++ Programmer’s Guide.

Example

// Assure that pMyObject is a valid pointer to an
// object derived from CObject.
ASSERT_VALID(pMyObject);

/
ASSERT
ASSERT( booleanExpression )

Parameters

booleanExpression

Specifies an expression (including pointer values) that evaluates to nonzero or 0.

Remarks

Evaluates its argument. If the result is 0, the macro prints a diagnostic message and aborts the program. If the condition is nonzero, it does nothing.

The diagnostic message has the form

assertion failed in file in line

where name is the name of the source file, and num is the line number of the assertion that failed in the source file.

In the Release version of MFC, ASSERT does not evaluate the expression and thus will not interrupt the program. If the expression must be evaluated regardless of environment, use the VERIFY macro in place of ASSERT.

Note This function is available only in the Debug version of MFC.

Example

// example for ASSERT
CAge* pcage = new CAge( 21 ); // CAge is derived from CObject.
ASSERT( pcage!= NULL )
ASSERT( pcage->IsKindOf( RUNTIME_CLASS( CAge ) ) )
// Terminates program only if pcage is NOT a CAge*.

你可能感兴趣的:(VC++)