Program to overload < and > to compare two strings [closed]

There are different things that can be called strings in C++, std::string is the main one, and that already provides those operators. C-style null terminated strings are another, and string literals yet another. For the latter two, you cannot overload operator< or operator>, as you can only overload operators for user defined types.

Even if you were allowed to overload the operators, they would misbehave in obscure ways, as the set of associated namespaces for const char* (or char* for that matters) is empty, Argument Dependent Lookup would fail to find your overload if it finds a different operator earlier during regular lookup.

Browse More Popular Posts

Leave a Comment