//注意,这个断言只在DEBUG状态下有效,如改成发行版它将会和它判断的语句 //一起消失,而VERIFY只会消失自己,不会将它的语句消失。 ASSERT ASSERT( booleanExpression )ParametersbooleanExpressionSpecifies an expression (including pointer values) that evaluates to nonzero or 0.ResEvaluates 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 formassertion 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*.
当表达式expression为真时,此语句相当于没有存在,为假时弹出assert failed 对话框,用来保证expression为真
如ASSERT(a)
如果a=0,就不下去了,可以保证a!=0
//一起消失,而VERIFY只会消失自己,不会将它的语句消失。
ASSERT
ASSERT( booleanExpression )ParametersbooleanExpressionSpecifies an expression (including pointer values) that evaluates to nonzero or 0.ResEvaluates 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 formassertion 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*.
用来判断该expression是不是成立,若不成立则会跳出一个异常对话框。因为在你开始一段程序时候,expression是一个你默认成立的条件,它如果不成立的话,对于你程序的运行将可能是致命的,所以你应该先确认一下你要求的条件是否成立,以保证你程序的健壮性。
是不是就如glassshark(追赶蜗牛)兄所言的那样的?仅仅是在debug和release条件下的对前者相当于失效,而后者仍旧起作用?
如改成发行版(Release)它将会和它判断的语句一起消失,而VERIFY只会消失自己,不会将它的语句消失。"所以兄弟们编程时不要为了省事而用它!该用if时就用if!