title: Using an STL algorithm on vector of pointers of an object (C++)
body: <p>I need to count the number of times an object of an array of pointers has the same name(member variable) as the parameter given to a member function. I have tried different approaches, but none of them worked. My code does not even compile. The error is: "error C2514: 'MyComparator' : class has no constructors" and here is the code of the class I use for the comparision and the function used for counting concurencies.</p>
  
  <pre><code> //definition of the vector
   vector&lt;Class1*&gt; files;
   ...
   int Class2::countNames(string name)
      {
         return count_if(files.begin(), files.end(), bind2nd(MyComparator(),name));
      }
   ...
  class MyComparator{
  public:
   bool operator()(const CFileType*&amp; ob1, const string &amp;str)
   {
     return ob1-&gt;getName()==str;
   }
  };
  </code></pre>
  
  <p>I am struggling with this for hours and I want to do it using STL. The catch here is that i have an vector of pointers, if I had a normal vector it would not need a predicate function, in my case I have to give a parameter to it and I think bind2nd() is the right way. Any help would be greatly appreciated!</p>