class error_code
{
...
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error
{
return m_val == 0 ? 0 : unspecified_bool_true;
}
...
}
这会导致可以检查这样的错误。
...
boost::system::error_code err
some_boost_func(err);
if(err)
{
//handle error
}
....
所以我一直在问自己...那里发生了什么事?
这似乎与函数指针的使用有关...
如果我调用err
,这会评估函数本身还是函数指针?
但是,一个void (*unspecified_bool_type)();
函数如何返回值?
return m_val == 0 ? 0 : unspecified_bool_true;