You are not storing object
s in your multiset
. You are storing object*
s. These are pointers to object
s. This means the set will order the pointers that you're inserting into it.
It seems like you really just want a multiset<object>
:
multiset<object> mmset;
mmset.emplace(10, "test");
mmset.emplace(11, "test");
Now it will use <
to compare the object
s themselves.
If you really want to store pointers, you'll need to provide a custom comparator to the multiset
. In C++11, you can do this easily with a lambda:
auto f = [](int* a, int* b) { return *a < *b; };
std::multiset<int*, decltype(f)> mmset(f);
Pre-C++11, you can create a function object that implements operator()
with the same body as this lambda function.