Why do we need empty classes in the first place? Any article or example that
could explain this to me?
They are useful in a number of contexts:
1. A class can define an interface, but its implementation may be in terms
of another facility defined at a lower level. For example, the class
template std::allocator is defined in terms of the global operators new and
delete. It requires no state of its own, but because it is a class, it can
have data members, and those members may be unique to each instance.
2. It is possible to define class templates that contain nothing but
typedefs that ease (somewhat) the creation of classes that must also define
those typedefs; the latter can derive publicly from the former. An example
would be std::iterator.
3. It is possible to define classes other classes can derive from in order
to indicate type categories. Examples would be std:
utput_iterator_tag,
std::input_iterator_tag, etc.
4. I once needed a standard way to create a unique type U<T> from a given
type T, because using T directly would interfere with the user's use of a
related facility, and an empty class template provided a way to do that.
5. Classes can be template arguments.
6. Classes have type_info, and map keys can be derived from type_info.
None of the above are possible with namespaces, which are similar to empty
classes that contain nothing but public static members and whose ctors,
dtor, and assignment operator are all private and unimplemented. (Well, I
suppose the first half of (1) can be done with namespaces.)