title: How do C++ functor constructors get called when used with for_each or std::transform
body: <p>I've never used c++ functors before and so I'm just trying to understand how they work.</p>
  
  <p>e.g. suppose we have this functor class</p>
  
  <pre><code>class MultiplyBy {
  private:
      int factor;
  
  public:
      MultiplyBy(int x) : factor(x) { }
  
      int operator () (int other) const {
          return factor * other;
      }
  };
  </code></pre>
  
  <p>Using it like this is clear to me:</p>
  
  <pre><code>MultiplyBy mult_3(3);
  
  int x = mult_3(100);
  </code></pre>
  
  <p>Obviosuly the constructor of MultiplyBy is being called with the argument 3.</p>
  
  <p>But in the following case, how is the constructor being called with the value in the array?</p>
  
  <pre><code>int array[5] = {1, 2, 3, 4, 5};
  std::transform(array, array + 5, array, MultiplyBy(3));
  </code></pre>