我正在尝试按照此页面上的示例进行操作:
http://www.boost.org/doc/libs/1_40_0/libs/exception/doc/motivation.html
我尝试以下一行的那一刻:
throw file_read_error() << errno_code(errno);
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
error C2440: '<function-style-cast>' : cannot convert from 'int' to 'errno_code'
Run Code Online (Sandbox Code Playgroud)
我如何让它工作?
理想情况下,我想创建这样的东西:
typedef boost::error_info<struct tag_HRESULTErrorInfo, HRESULT> HRESULTErrorInfo;
Run Code Online (Sandbox Code Playgroud)
但我甚至无法得到第一个可行的例子.
编辑:以下是为我生成错误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);
}
Run Code Online (Sandbox Code Playgroud) c++ error-handling boost exception-handling visual-studio-2008