MFC的诊断函数AssertValid通常在DEBUG版本的什么时候调用?还是要我在程序中自行调用?

解决方案 »

  1.   

    在程序中需要处加上
    AssertValid(...);
    运行到这里时就可以诊断了,而编译非DEBUG版本AssertValid的语句将被忽略。
      

  2.   

    当然你也可人为的加上,参照VC程序的用法。抄MSDN的,对照VC程序来看
    AssertValid 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. 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 object’s class. 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.