5

I'm using dlib.

I came across the following in one of the example programs:

cout << "p(D=0) = " << solution.probability(D)(0) << endl;

I've never seen a double parenthesis after a function call in C++. What does it do and how does it work?

Pétur Ingi Egilsson
  • 4,368
  • 5
  • 44
  • 72
  • 1
    I would guess that `solution.probability(D)` return a single parameter functor, which you then call with argument `0`. – juanchopanza Nov 28 '13 at 17:07
  • 1
    probability(D) likely returns a function pointer. http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work – kenny Nov 28 '13 at 17:07
  • `probability` is a function returning another function pointer, `std::function`, etc. Its return value is called again. –  Nov 28 '13 at 17:07

1 Answers1

13

What does solution.probability(D) return. If it's a functional object, or a pointer to a function, you can call it, which is probably what the second set of parentheses do.

James Kanze
  • 150,581
  • 18
  • 184
  • 329