title: Get the dot product of two vectors by functors and STL algorithms
body: <p>I'm learning how to use functors together with STL algorithms to calculate the dot product of two vectors. Here are my codes:</p>
  
  <pre><code>template&lt;size_t DIM&gt;
  double Vector&lt;DIM&gt;::operator*(const Vector&lt;DIM&gt;&amp; rhs) const {
      double dotPro = 0;
      std::for_each(vec, vec + DIM, std::bind2nd(dot_product&lt;double&gt;(rhs.get()), dotPro));
      return dotPro;
  }
  /*vec is a double array and the data member of Vector class. I want to get the 
  dot product of rhs and *this by using std::for_each(). 
  rhs.get()returns a const double* which is the start address of rhs's vec*/
  
  /*The codes below define the functor.  dotPro is passed as a reference so as to 
  it could be save the last result.*/  
  template&lt;typename T&gt;
  struct dot_product: public std::binary_function&lt;T, T, void&gt; {
      const T* arg;
      sum(const T* dbl) : arg(dbl){};
       void operator() (const T dbl, T&amp; dotPro) {
          dotPro += *arg++ * dbl;
      }
  };
  </code></pre>
  
  <p>Sorry I forget my quesion...
  The question is my code doesn't compile. Here is the compiling error:</p>
  
  <pre><code>error: no match for call to '(const dot_product&lt;double&gt;) (const double&amp;, const double&amp;)'|
  note: candidates are: void dot_product&lt;T&gt;::operator()(T, T&amp;) [with T = double]|
  </code></pre>
  
  <p>And here is a error occurs in binders.h</p>
  
  <pre><code>c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\backward\binders.h|147|error: return-statement with a value, in function returning 'void'|
  </code></pre>