【发布时间】:2013-10-12 15:22:54
【问题描述】:
我正在编写一个自定义 Exception 类,与 std::exception 相比具有一些附加功能。我在我的 Exception 类中添加了一个自定义构造函数 Exception(std::string details) : details(details) {}。
稍后,当我使用类FileNotAccessibleException 扩展Exception 类并抛出它时,我得到一个编译错误,说no matching function for call to ‘FileNotAccessibleException::FileNotAccessibleException(std::basic_string<char>)’ 当我向我的类添加一个方法FileNotAccessibleException(std::string details) : Exception(details) {} 时,它确实有效美好的。
有没有办法让构造函数工作,而不必为我的所有类重新定义构造函数?
【问题讨论】:
-
是的,使用继承构造函数。
标签: c++ exception methods constructor