0

I have simple question, and yet i could not find any answer.

Let's say i have a function object:

template <typename T>
class MyFunctionObject {
private:
    //...
public:
    double operator()(T value) {
        //...
        return double_value;
    }
}

What is the difference between those two "lines":

double value = MyFunctionObject <int> ()(1000);

and

MyFunctionObject <int> functor;
double value = functor(1000);
PatrykB
  • 1,579
  • 1
  • 15
  • 24
  • Very little, except that in the first the functor isn't named. – Carcigenicate Jul 02 '17 at 15:26
  • @Carcigenicate in the 1st case; when functor will go out of scope? Right after execution, or at the end of the local scope (function in with it is called)? – PatrykB Jul 02 '17 at 15:28
  • If that's your question, it looks like this may be a duplicate of https://stackoverflow.com/questions/584824/guaranteed-lifetime-of-temporary-in-c My C++ is rusty though, so I can't answer that. I also didn't vote to close as a duplicate since I'm not sure. Read the link over though. – Carcigenicate Jul 02 '17 at 15:30
  • 4
    The lifetime of the first function object expires after the expression is evaluated. – Blastfurnace Jul 02 '17 at 15:31
  • @Carcigenicate OP's question in the comments is the same as your link, although the question as it is posted is not – Passer By Jul 02 '17 at 15:43
  • @PasserBy That's true. Nix the duplicate part of the comment. Still worth a read-over though. – Carcigenicate Jul 02 '17 at 15:47

0 Answers0