Skip to content

Commit 30a6ca2

Browse files
Make operator<=> friend.
1 parent 65d08b8 commit 30a6ca2

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎CPP20.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ struct foo {
260260
char c;
261261

262262
// Compare `a` first, then `b`, then `c` ...
263-
auto operator<=>(const foo&) const = default;
263+
friend auto operator<=>(const foo&) const = default;
264264
};
265265

266266
foo f1{0, false, 'a'}, f2{0, true, 'b'};
@@ -275,7 +275,8 @@ struct foo {
275275
int x;
276276
bool b;
277277
char c;
278-
std::strong_ordering operator<=>(const foo& other) const {
278+
279+
friend std::strong_ordering operator<=>(const foo& other) const {
279280
return x <=> other.x;
280281
}
281282
};

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ struct foo {
364364
char c;
365365

366366
// Compare `a` first, then `b`, then `c` ...
367-
auto operator<=>(const foo&) const = default;
367+
friend auto operator<=>(const foo&) const = default;
368368
};
369369

370370
foo f1{0, false, 'a'}, f2{0, true, 'b'};
@@ -379,7 +379,8 @@ struct foo {
379379
int x;
380380
bool b;
381381
char c;
382-
std::strong_ordering operator<=>(const foo& other) const {
382+
383+
friend std::strong_ordering operator<=>(const foo& other) const {
383384
return x <=> other.x;
384385
}
385386
};

0 commit comments

Comments
 (0)