What happened to std::assert

2019-02-14 07:03发布

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?

2条回答
欢心
2楼-- · 2019-02-14 07:37

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-02-14 07:53

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

查看更多
登录 后发表回答