首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有调用‘boost::property_tree::ptree_bad_data::ptree_bad_data()的匹配函数

没有调用‘boost::property_tree::ptree_bad_data::ptree_bad_data()的匹配函数
EN

Stack Overflow用户
提问于 2017-09-27 08:17:48
回答 1查看 534关注 0票数 0

我的自定义异常类派生自数据,如下所示:

代码语言:javascript
复制
class MyCustomException : public boost::property_tree::ptree_bad_data
{
    public:
      explicit MyCustomException(const std::string& msg): mMsg(msg) {}
      virtual ~MyCustomException() throw() {}
      virtual const char* what() const throw() { return mMsg.c_str(); }

    private:
      std::string mMsg;
};

在编译过程中,我得到的错误如下:

error: no matching function for call to ‘boost::property_tree::ptree_bad_data::ptree_bad_data()’ explicit MyCustomException(const std::string& msg): mMsg(msg) {} ^ note: candidate expects 2 arguments, 0 provided explicit MyCustomException(const std::string& msg): mMsg(msg) {} ^

知道原因是什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-27 08:55:56

根据文档,类ptree_bad_data没有无参数构造函数。它实际上只有一个构造函数:

代码语言:javascript
复制
template<typename T> ptree_bad_data(const std::string &, const T &);

因此,您必须在构造函数中提供这两个参数:

代码语言:javascript
复制
explicit MyCustomException(const std::string& msg)
    : boost::property_tree::ptree_bad_data(msg, nullptr /* correct data here */)

您的异常类也不需要单独存储异常消息。标准异常类将为您执行此操作。

顺便说一句,您确定要从ptree_bad_data派生异常吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46442777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档