title: how to store polymorphic object in set
body: <p>how to define overloaded comparison operator or comparison functor, so that i can create the set of class A. i have a class Base which have int member variable _state and a derived class A.</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;set&gt;
  class Base{
  int _state;
  protected:
      virtual void fun() = 0;
  public:
  bool operator &lt; (const Base &amp; t)
  {
  return (this-&gt;_state &lt; t._state);
  }
      Base (int s): _state(s){}
      virtual ~Base() = default;
  };
  
  class A: public Base{
  public:
      A(int s): Base(s){}
      void fun() override{}
      
  };
  
  int main()
  {
      A a(5);
      
      std::set&lt;A&gt; s;
      
      s.insert(a);
      
      return 0;
  }
  </code></pre>