c++ - Can I call directly operator() without creating a temporary object? -


i've following utility function convert given string integer.

class converttoint:public std::unary_function<const char*, int> {          public:                 int operator()(const char* cnumber)                 {                         try                         {                                 int result = boost::lexical_cast<int>(cnumber);                                 return result;                         } catch ( boost::bad_lexical_cast& error)                         {                                 std::cerr << "error in converting number "<< error.what() << std::endl;                                 return -1;                         }                 }  }; 

when want use utility function, i've following.

  converttoint cstrtoint;   int inumbertocheck = cstrtoint(argv[1]); 

i'm wondering, there way, can directly call

int inumbertocheck = converttoint(argv[1]); 

no, member function , requires object invoked on. use unnamed temporary instead:

int inumbertocheck = converttoint()(argv[1]); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -