gpt4 book ai didi

linux - std::exception(const char*) 非标准构造函数的替代方法

转载 作者:IT王子 更新时间:2023-10-28 23:59:32 25 4
gpt4 key购买 nike

我的 Visual C++ 代码使用接受字符串的 std::exception 构造函数,我正在尝试将代码移植到 Linux/G++。我应该使用什么异常类?

最佳答案

Microsoft Visual C++ 的 std::exception(const char*)构造函数是非标准的。在 C++ 标准库中,std::exception 有一个 const char* what() const方法,它不提供指定字符串的方法,除非通过覆盖。

您应该重写代码以使用 std::runtime_error或来自 <stdexcept> 的其他类别之一作为备选。当然,不需要更改捕获 std::exception 的现有代码,因为 std::runtime_error 派生自它。

关于linux - std::exception(const char*) 非标准构造函数的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com