title: How can I define == operator when comparing vectors of classes and objects?
body: <p>I want my program to stop when vector has the same colors over 3 times.
  Here, I used 'if(b==all_colors[i])' but I'm getting the error.
  Is this because I didn't use the template ? Do I have to rewrite the whole code?</p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;sstream&gt;
  #include&lt;vector&gt;
  
  using namespace std;
  
  class Bag
  {
      string marble;
  
  public:
      Bag(string marble)
      {
          this-&gt;marble=marble;
      }
  
      string add_marble()
      {
          return marble;
      }
  };
  
  class Marble_exception
  {
      vector&lt;Bag&gt;all_colors;
      int count=0;
  
  public:
      void add_color(Bag b)
      {
          for(int i=0; i&lt;all_colors.size(); i++)
          {
              if(b==all_colors[i])
              {
                  count++;
              }
          }
  
          if(count&gt;=3)
          {
              cout&lt;&lt;&quot;Sorry, you already have three of these marbles.\n\n&quot;;
          }
          else
          {
              all_colors.push_back(b);
              cout&lt;&lt;&quot;added.\n\n&quot;;
          }
      }
  };
  
  </code></pre>