title: C++ Functor Syntax
body: <p>I have a question regarding the syntax of how to call a functor in C++. In the code below, why do the first 2 examples work whilst the 3rd and 4th attempt do not?</p>
  
  <p>Also I can call <code>ob (100);</code> and it will output <code>300</code>, but why can't I call <code>Class(100)</code> and have it output <code>300</code>? Is there any way to use the overloaded operator <code>()</code> without instantiating a new object?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;functional&gt;
  
  using namespace std; 
  
  
  struct Class
  { 
      void operator() (int a) 
      { 
          cout &lt;&lt; a * 3 &lt;&lt; " "; 
      } 
  } ob; 
  
  
  int main() 
  { 
  
      int arr[5] = { 1, 5, 2, 4, 3 }; 
  
      cout &lt;&lt; "Multiple of 3 of elements are : "; 
      for_each(arr, arr + 5, Class());
      cout &lt;&lt; endl; 
      for_each(arr, arr + 5, ob); 
      cout &lt;&lt; endl; 
  
      // Why do these not work???
      for_each(arr, arr + 5, Class);
      for_each(arr, arr + 5, ob());
  
  }
  </code></pre>