[英]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.