【问题标题】:Compilation error in list while using C++11使用 C++11 时列表中的编译错误
【发布时间】:2020-04-20 19:47:09
【问题描述】:

使用 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 编译它。

【问题讨论】:

  • 奇怪。这是第一个错误和整个错误消息吗?
  • 你做了一些奇怪的事情。无论放入列表中的类都无法创建is_nothrow_default_constructible 模板。由于它唯一能做的事情是真或假,这意味着很可能根本无法构造该类。我们肯定需要查看更多代码。并且一定要尝试制作一个只包含一个类而不是所有 Qt 垃圾的小型测试程序,看看它是否可以编译。
  • 我的超能力表明,在 2005 年至 2011 年间开发的 Qt 4 不符合 C++11。
  • @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) 以消除错误。谢谢。

标签: c++ qt c++11 compiler-errors noexcept


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-01-24
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多