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

后端 未结 11 1220
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  萌比男神i
    2020-12-24 08:14

    Microsoft-specific CRT asserts

    #include 
    #include 
    ...
    // displays nondescript message box when x <= 42
    _ASSERT(x > 42);
    // displays message box with "x > 42" message when x <= 42
    _ASSERTE(x > 42);
    // displays message box with computed message "x is ...!" when x <= 42
    _ASSERT_EXPR(
       x > 42, (std::stringstream() << L"x is " << x << L"!").str().c_str());
    

提交回复
热议问题