function::operator 未指定

测试,如果存储可调用对象存在。

operator unspecified();

备注

运算符返回转换成一个有效值的 bool 值,对象才不为 null。 您可用它测试对象是否为空。

示例

 

// std_tr1__functional__function_operator_bool.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
int neg(int val) 
    { 
    return (-val); 
    } 
 
int main() 
    { 
    std::function<int (int)> fn0; 
    std::cout << std::boolalpha << "not empty == " << (bool)fn0 << std::endl; 
 
    std::function<int (int)> fn1(neg); 
    std::cout << std::boolalpha << "not empty == " << (bool)fn1 << std::endl; 
 
    return (0); 
    } 
 
  

要求

标头: <起作用的>

命名空间: std

请参见

参考

function 类

bad_function_call 类