title: C++: use own class in a multiset container
body: <p>at first I'm new here and English isn't my native language so apologize for any grammatical failures but I find this community really nice so I will try to ask my question as precise as I can.</p>
  
  <p>I want to add my own class object into a stl container multiset and want to sort it with my own overloaded less operator defined in my class. I really tried out several solutions but nothing really worked so I hope someone can give me some useful hints to solve it.</p>
  
  <p>Here is my general idea of my class definition:</p>
  
  <pre><code>class object {
  public:
      int first;
      string second;
  
      object(int f, string s) {
           first = f;
           second = s;
      }
  
      bool operator&lt;(const object &amp;comp) {
          return first &lt; comp.first;
          }
  };
  </code></pre>
  
  <p>This was my first try and it didn't work so I also tried out to declare the overloaded operator as a friend method but it didn't work also.</p>
  
  <p>Here is a short code extract from my main function:</p>
  
  <pre><code>includes ...
  //code omitted
  int main() {
      multiset&lt;object*&gt; mmset;
  
      mmset.insert(new object(10, "test"));
      mmset.insert(new object(11, "test"));
  
      return 0;
   }
  </code></pre>
  
  <p>After a while I started to debugging my code and try to figure out where the problem is and I come across the following thing that have made me a bit suspicious.</p>
  
  <p>code extract from the stl:</p>
  
  <pre><code>// TEMPLATE STRUCT less
  template&lt;class _Ty&gt;
  struct less : public binary_function&lt;_Ty, _Ty, bool&gt;
      {   // functor for operator&lt;
      bool operator()(const _Ty&amp; _Left, const _Ty&amp; _Right) const
      {   // apply operator&lt; to operands
            return (_Left &lt; _Right);
      }
      };
  </code></pre>
  
  <p>I have set a breakpoint on this line and observed what the program is doing here and I don't know why, but it only compares the addresses from the two objects and return so always false. It never calls my overloaded less operator although the operator exists and the _Left and _Right variables contain the address to my object.</p>
  
  <p>I would really appreciate it if someone could help me.</p>
  
  <p>Best Greetings</p>
  
  <p>Tom</p>