【问题标题】:missing std::runtime_error in qt+mingwqt+mingw 中缺少 std::runtime_error
【发布时间】:2011-02-01 11:09:46
【问题描述】:

我尝试使用 Qt(4.6.3) + MinGW 编译以下代码:

#include <QtCore/QCoreApplication>
#include <exception>

int main(int argc, char *argv[])
{
    throw std::runtime_error("");

    QCoreApplication a(argc, argv);

    return a.exec();
}

...并得到这个错误:

..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std'

从头开始创建的项目(控制台应用程序),pro 文件:

QT       += core

QT       -= gui

TARGET = untitled11
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

尝试使用 Qt+MSVC2008 编译器进行编译 - 工作正常。

这是一个标准异常,不知道为什么会丢失。

【问题讨论】:

    标签: qt mingw runtime-error


    【解决方案1】:

    &lt;exception&gt; 仅定义基类 std::exceptionclass;如果你想要像std::runtime_error 这样的子类,你必须包含&lt;stdexcept&gt; 标头。

    【讨论】:

    • 它存在,并且包含基本的std::exception 类,而&lt;stdexcept&gt; 包含标准的子异常类。 cplusplus.com/reference/std/exception
    • +1000 在使用 std::invalid_argument 时让我发疯了(在 Ubuntu 上,gcc 4.7)。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 2021-11-05
    • 2010-12-06
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多