The code is shown here:
class Basket{
public:
/*other contents*/
private:
// function to compare shared_ptrs needed by the multiset member
static bool compare(const std::shared_ptr<Quote> &lhs,
const std::shared_ptr<Quote> &rhs)
{ return lhs->isbn() < rhs->isbn(); }
// multiset to hold multiple quotes, ordered by the compare member
std::multiset<std::shared_ptr<Quote>, decltype(compare)*>
items{compare};
};
We initialize our multiset through an in-class initializer. Commonly we put a same class object in the curly bracket. Why a function can be put here? I can't understand;
It's explained in the book C++ primer like it: The multiset will use a function with the same type as our compare member to order the elements. The multiset member is named items, and we’re initializing items to use our compare function.
I can understand the logic, but what is the syntax used here?