What is the best way of implementing assertion checking in C++?

后端 未结 11 1250
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 07:31

By that I mean, what do I need to do to have useful assertions in my code?

MFC is quite easy, i just use ASSERT(something).

What\'s the non-MFC way?

11条回答
  •  没有蜡笔的小新
    2020-12-24 08:26

    To answer the asker's third question: the first reason we use "cassert" instead of "assert.h" is because, in the case of C++, there's an allowance made for the fact that the C++ compiler may not store the function descriptions in code files, but in a dll or in the compiler itself. The second is that there may be minor changes made to functions in order to facilitate the differences between C and C++, either present or in the future. Because assert.h is a C library, the preference is to use "cassert" while in C++.

提交回复
热议问题