The difference between set and multiset is, multiset allows duplicates, but sets don't. More importantly, both set and multiset maintain an order, in which they store the elements. To be brief, both set and multiset use a Red-Black Tree (an advanced form of balance binary tree) to store their elements, so you need to have an order in which the elements will get inserted.

The elements of a set of multiset may have any type T that is assignable, copyable and comparable according to some sorting criterion. The optional second argument holds the stands for this comparison based operation. If a special sorting criterion is not passed while declaring a set and/or multiset, the default std::less<> is used by the container.

So, now if you need to push a bunch of custom objects (objects of your own class), how can you design your class so that they can be contained in set/multiset.

As I said earlier: "The elements of set/multiset can be of any type T, that is:

Assignable (that is you have to have an overloaded assignment operator, or default assignment operator - if it is sufficient enough to do the job)

Copyable (that is you have to have an copy constructor, or default copy constructor - if it is sufficient enough to do the job)

Comparable: This is the most important part. You have to put some kind of decision making branch which will compare two custom defined objects based on some comparison criteria. Here you have two choices:

You can overload a "<" operator inside your class itself.

You can create a functor to do the comparison job.

Another important thing is, the sorting criterion must define "String Weak Ordering". Strict Weak Ordering is defined by following three properties:

It has to be anti-symmetric, aka if x<y is true then y<x is false.

It has to be transitive: aka, if x<y is true and y<z is true then x<z is also true.

Here the custom typedef line is the most important one, just look at the declaration carefully, here we are declaring a std::set which will hold our custom types and will compare based on the functors we have. Again, MyComparator declaration inside std::set declaration also needs to hold the type definition of our customized class, since our functor is also templated.

Yes partly true. Here I described both the way you can do. Which implies you can only choose to write your own comparator (functor) and can simply ignore the overhead of "Operator overloading", in that case you'll be in trap.

Sorry mate, probably you missed out the theme of this article. This article has nothing to do with "Multiple types in a Set", it is indeed an explanation about what all steps you need to take if you want to insert a/bunch of user defined object in a set/multiset.