How to use boost::error_info correctly?

Viewed 12635

I'm trying to following the examples on this page:

http://www.boost.org/doc/libs/1_40_0/libs/exception/doc/motivation.html

The minute I try the following line:

throw file_read_error() << errno_code(errno);

I get an error:

error C2440: '<function-style-cast>' : cannot convert from 'int' to 'errno_code'

How do I get this to work??

Ideally I want to create something like this:

typedef boost::error_info<struct tag_HRESULTErrorInfo, HRESULT> HRESULTErrorInfo;

But I can't even get the first examples to work.

Edit: Here is a brief example of what generates error C2440 for me:

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);
}
3 Answers
Related