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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -