What happened to std::assert

穿精又带淫゛_ 提交于 2019-11-30 03:47:17

问题


This answer and it's multitude of duplicates indicate that I should be using #include <c*> for the C headers that I pull from in C++ code, and that I should be calling them with std::*.

I have been doing that but I notice an exception. std::assert doesn't seem to be defined, even when I correctly #include <cassert>.

What's going on here? Is this an implementation oversight, or an actual exception?


回答1:


assert is a macro, not a function. Hence, it needs to be used with plain old assert(condition).

Here's a supporting link: http://en.cppreference.com/w/cpp/error/assert.




回答2:


assert is a macro, thus it isn't possible to restrict it to a namespace.



来源:https://stackoverflow.com/questions/37124192/what-happened-to-stdassert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!