In C++ primer 5 ed. by Stanley lipmann chapter 15 OOP it is said:
std::multiset<std::shared_ptr<Quote>, decltype(compare)*> items{compare};
The elements in our multiset are shared_ptrs and there is no less-than operator for shared_ptr. As a result, we must provide our own comparison operation to order the elements (§11.2.2, p. 425). Here, we define a private static member, named compare, that compares the isbns of the objects to which the shared_ptrs point. We initialize our multiset to use this comparison function through an in-class initializer (§7.3.1, p. 274):"
But If I try this:
// a class that doesn't define < operator
struct A
{
int x = 0;
};
int main()
{
std::shared_ptr<A> pa(make_shared<A>());
std::shared_ptr<A> pb(make_shared<A>());
cout << (pb < pa) << endl; // 0
}
Why my code works although class
A
doesn't define less than operator?The thing is that after checking cppreference about
class std::shared_ptr
I've found out that it has overloaded relational operators?!I've also compiled the code against C++11 and still works fine!
So I'd like someone to explain to me that paragraph in the book. Thank you!