【发布时间】:2011-04-16 11:31:35
【问题描述】:
我正在尝试遵循此页面上的示例:
http://www.boost.org/doc/libs/1_40_0/libs/exception/doc/motivation.html
我尝试以下行的那一刻:
throw file_read_error() << errno_code(errno);
我收到一个错误:
error C2440: '<function-style-cast>' : cannot convert from 'int' to 'errno_code'
如何让它工作?
理想情况下,我想创建这样的东西:
typedef boost::error_info<struct tag_HRESULTErrorInfo, HRESULT> HRESULTErrorInfo;
但我什至无法让第一个示例工作。
编辑:以下是我生成错误 C2440 的简要示例:
struct exception_base: virtual std::exception, virtual boost::exception { };
struct io_error: virtual exception_base { };
struct file_read_error: virtual io_error { };
typedef boost::error_info<struct tag_errno_code,int> errno_code;
void foo()
{
// error C2440: '<function-style-cast>' : cannot convert from 'int' to 'errno_code'
throw file_read_error() << errno_code(errno);
}
【问题讨论】:
-
您能否发布一个在遇到 C2440 错误时尝试编译的完整最小示例?
-
查看链接上的示例。我无法让
throw file_open_error() << errno_code(errno);工作。 -
对于遇到这种情况的其他人:Boost Exception 文档中的“动机”页面不完整——这里有一个更好的例子:boost.org/doc/libs/1_56_0/libs/exception/doc/…,他们列出了正确的标题。
标签: c++ visual-studio-2008 boost exception-handling error-handling