There are three ways to initialize a data member of a class type object:
struct S{ int x{42}; };
struct T{ int x = 42; };
struct U{ int x; U():x{42}{} };
The last one defines a default constructor for `U`.
The two first specify a default initialization that can be overridden by
a constructor, and if it's not overridden it is as if it was done by the
constructor like the one in `U`.
• • •
I assume that you're doing this for learning & language exploration.
But for practical programming just do as Mr. Flibble wrote:
define an `operator<` for the class, e.g. like this:
struct Point
{
int x = 0;
int y = 0;
friend
auto operator<( Point const& a, Point const& b )
-> bool
{ return tie( a.x, a. y ) < tie( b.x, b.y ); }
};
… where `tie` is `std::tie` from the `<tuple>` header.
• • •
An alternative to `tie` and that kind of stuff, is to define a
three-valued `compare` function, like `std::string::compare`, and then
inherit from a class template that defines `<` and other relational
operators in terms of `compare`. The inherit-in-an-implementation is
called the Barton-Nackman trick. It's in Wikipedia and other places.
Cheers & hth.,
- Alf