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 <name> in line <num>

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*.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值