繁体   English   中英

消息“错误:使用未声明的标识符‘断言’”

[英]Message "error: use of undeclared identifier 'assert'"

我有一段代码,其中包含一些 Boost 标头。 编译后,我收到了类似的错误

/usr/local/include/boost/smart_ptr/shared_ptr.hpp:1041:9: error: use of undeclared identifier 'assert'

        BOOST_ASSERT( deleter_.use_count() <= 1 );

        ^

/usr/local/include/boost/assert.hpp:60:29: note: expanded from macro 'BOOST_ASSERT'

# define BOOST_ASSERT(expr) assert(expr)
                                ^

然而,这些错误只发生在 Windows 和 macOS 上。

在 Boost 头文件之前显式包含<cassert><assert.h>无效。

您需要#include <cassert>来引入assert实现。

相应地定义或不定义NDEBUG是您的工作。

我很惊讶 Boost 并没有为您做到这一点 - 您是否正确使用了 Boost 文件(即包括您应该使用的文件)?

事实证明,我的包含路径中有一个名为Assert.h的文件(我的自定义文件)。 在 Windows 和 macOS 使用的不区分大小写的文件系统上,这将assert.h实际定义assert宏的原始assert.h标头。

因此,解决方案只是重命名我的断言头文件。

(由于[Compilation Error] error: use of undeclared identifier 'assert' #15 ,我找到了解决方案。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM