Error no matching function for call to 'std::exception::exception(const char [15])'

Error 'logic_error' was not declared in this scope

错误原因

C++在使用VS 编译时抛出异常可以用下列语句:

throw std::exception("XXX");

但使用Dev-C++ (GCC) 编译时,会报以下错误:

Error no matching function for call to 'std::exception::exception(const char [15])'

解决方法:

#include <stdexcept>
throw std::logic_error("XXX");

如果不  #include <stdexcept>  则会报错:

Error 'logic_error' was not declared in this scope

附:

标准异常阶层体系


参考: 
http://www.cplusplus.com/forum/beginner/107744/
https://blog.csdn.net/xiajun07061225/article/details/8231270
https://blog.csdn.net/fengbingchun/article/details/78303734

Error no matching function for call to 'std::exception::exception(const char [15])'的更多相关文章

  1. error: no matching function for call to 'std::exception:exception(const char[16])'

    环境:codeblocks 语言:C++ 在执行:throw new exception("queue is empty.");时 遇到问题:error: no matching ...

  2. 【ERROR】no matching function for call to 'std::basic_ifstream<char>::basic_ifstream

    错误记录:QT中使用 no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(QString ...

  3. boost::bind 不能处理函数重载 (error: no matching function for call to 'bind')

    前言 最近任务多.工期紧,没有时间更新博客,就水一期吧.虽然是水,也不能太失水准,刚好最近工作中遇到一个 boost::bind 的问题,花费了半天时间来定位解决,就说说它吧. 问题背景 项目中使用了 ...

  4. How to convert a std::string to const char* or char*?

    How to convert a std::string to const char* or char*? 1. If you just want to pass a std::string to a ...

  5. std::string stringf(const char* format, ...)

    std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 ...

  6. Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))

    connect(ui->spinBox_luminosity,&QSpinBox::valueChanged, ui->horizontalSlider_luminosity, & ...

  7. no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)

    使用string中的assign赋值函数报错,代码为: text0.assign(line,i+); 其中text0与line都为string类型 最后发现assign函数的原型为 string &a ...

  8. error: no matching function for call to 'Ui::GoToCellDialog::setupUi(QDialog*&)' ui.setupUi(dialog); ^

    环境:Qt5.3 参考书是:C++ GUI Qt4编程 问题描述: 按照书中的例子2-2做,编译时遇到的问题,从字面意思看是没有匹配的函数可用,UI::GotoCellDialog类是自动生成的,所以 ...

  9. g2o相关问题cs.h,以及no matching function for call to ‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(Block*&)

    1.对于cs.h找不到的情况 1)编译的时候一定要把csparse在EXTERNAL文件中,编译进去. 2)修改CMakeLists.txt文件中的include_directories中的${CPA ...

随机推荐

  1. Centos下用yum命令按照jdk

    一.查看是否已经安装了JDK #查看本机是否已经安装了jdk $ sudo yum list installed | grep java java--openjdk.x86_64 :.el7_6 @u ...

  2. Ubuntu16.04 / OpenCV / Python 源码安装

    为什么需要源码安装? 1. 对 Python 版的 OpenCV,Ubuntu 有两种安装方式: 源码安装:官网(https://opencv.org/releases.html)下载源代码,在机器上 ...

  3. ajax--底层代码

    ajax:Asynchronous JavaScript And XML,异步的js与XML.ajax并不是一种新的编程语言,而是一种使用现有标准的新方法.ajax能够在不重载整个网页的情况下与服务器 ...

  4. js02--对象、函数、switch、for、异常、表单验证

    现在我们接着来继续学习有关js的一些基础. 1.undefined与null    undefined:当变量声明但尚未赋值时,它的类型就是undefined    null:表示一个不存在的对象,它 ...

  5. 使用Intent在活动之间穿梭

    使用Intent在活动之间穿梭 1.在com.example.activitytest中创建第二个活动SecondActivity: /** * 第二个活动 */ public class Secon ...

  6. Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置

    不多说,直接上干货! 说明 图形界面安装,会自带有Centos6.5自带的OPRNJDK!!! *********************************自带的OPENJDK的卸载****** ...

  7. CRF两个例子的理解

    概率计算例子: 预测例子:

  8. java的日期格式化

    原博客地址: http://blog.csdn.net/yangbobo1992/article/details/9965105 日期格式: 时间日期标识符: yyyy:年 MM:月 dd:日 hh: ...

  9. java序列化测试

    0.前言 本文主要对几种常见Java序列化方式进行实现.包括Java原生以流的方法进行的序列化.Json序列化.FastJson序列化.Protobuff序列化. 1.Java原生序列化 Java原生 ...

  10. CentOS 7 安装 RabbitMQ 3.7

    目录 CentOS 7 安装 RabbitMQ 3.7 安装Erlang 安装依赖 创建yum源 参考 添加内容 安装 进入erlang命令行表示成功 安装 socat RabbitMQ 安装 sys ...