首页 > 解决方案 > 使用 C++11 时列表中的编译错误

问题描述

使用 std=c++11 选项编译 C++ 代码时出现以下错误。

In file included from /usr/include/c++/7/list:63:0,
                 from /usr/include/qt4/QtCore/qlist.h:51,
                 from /usr/include/qt4/QtCore/QList:1,

/usr/include/c++/7/bits/stl_list.h:591:68: error: ‘std::is_nothrow_default_constructible<typename std::__cxx11::_List_base<_Tp, _Alloc>::_Node_alloc_type>::value’ is not a type
       noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)

代码编译,如果我使用 std=c++98 选项!但我需要使用 C++11 编译它。

标签: c++qtc++11compiler-errorsnoexcept

解决方案


正如 ZanLynx 正确怀疑的那样,错误是从代码的其他部分引发的。我使用的是旧版本“0.9.9”SQLiteCpp (github.com/SRombauts/SQLiteCpp)。为了检测他们使用的 C++11 编译器#if (defined(GNUC) && (GNUC >= 4 && GNUC_MINOR >= 7 ) && defined(GXX_EXPERIMENTAL_CXX0X)),它没有按预期工作。我将其更改为#if (__cplusplus >= 201103L)删除了错误。谢谢赞林克斯!


推荐阅读