C++
No Match for Operator== Fix
Built-in types compare with == because the language defines that comparison for them. A class or struct gets no such comparison for free: unless the type itself declares an operator==, the compiler has nothing to call, and GCC answers 'no match for operator=='. This guide reads the diagnostic, separates the nearby cases that draw the same or a related error, and fixes the comparison by giving the type the operator it is missing: defaulted in C++20, or hand-written when the code must build as an earlier standard or member-wise equality is not the right rule.
Written November 28, 2026 · Tested with GCC 13.3.0 · 5 min read
- The failure: two objects, no equality operator
- Comparing against a different type keeps the same wording
- Comparing pointers is not comparing objects
- Defining only operator!= does not fix ==
Written November 28, 2026
Tested with GCC 13.3.0
What this guide is
Equality for a class type is opt-in. The compiler does not invent a member-by-member comparison on its own, because it cannot know whether two objects with equal members should count as equal in the program's terms. So a struct with two int members still has no == until the programmer declares one. The declaration is small, and in C++20 it can be a single defaulted line that asks the compiler to generate exactly that member-by-member comparison.
The error in this guide's title is what GCC says while that declaration is missing. The same wording also appears in two nearby situations covered below: comparing an object against a value of a different type that its operator== does not accept, and defaulting an operator== on a type whose member has no equality operator of its own. A fourth look-alike is not an error at all: comparing pointers to objects compiles without any operator==, because it compares addresses, not objects. Telling these apart matters, because only the first one is fixed by adding the missing operator to the type being compared.
Build every program in this guide with g++ -std=c++20 -g, except the two programs compiled with -std=c++17 where the standard itself is the point.
The failure: two objects, no equality operator
A point with two coordinates is the usual shape of this error. The struct is complete and usable in every other way; the comparison is the only line that fails:
#include <iostream>
struct Point {
int x;
int y;
};
int main() {
Point a{1, 2};
Point b{1, 2};
std::cout << std::boolalpha << (a == b) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o fail fail.cpp
fail.cpp: In function 'int main()':
fail.cpp:11:39: error: no match for 'operator==' (operand types are 'Point' and 'Point')
11 | std::cout << std::boolalpha << (a == b) << "\n";
| ~ ^~ ~
| | |
| | Point
| Point
Read the error in its parts. The operand types are named in the first line, Point and Point, and the diagram under the expression repeats them in order, left operand first. GCC is reporting a failed search, not a broken operator: it looked for a built-in candidate, a member candidate, and a free-function candidate for two Points, and found none it could call. The values in the two objects do not matter. a and b hold identical members here, and the error is the same, because the question is never reached. There is no function to ask it with.
The fix therefore belongs to the type, not to the call site. Both fixes at the end of this guide add an operator== to Point. Which one to use depends on the standard the code builds as and on whether member-by-member equality is the rule the program wants.
Comparing against a different type keeps the same wording
Adding an operator== for Point-to-Point comparison does not make every comparison involving a Point legal. Compare a Point against an int, and the title error returns, now with mismatched operand types:
#include <iostream>
struct Point {
int x;
int y;
bool operator==(const Point&) const = default;
};
int main() {
Point a{1, 2};
std::cout << std::boolalpha << (a == 2) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o diff-type diff-type.cpp
diff-type.cpp: In function 'int main()':
diff-type.cpp:11:39: error: no match for 'operator==' (operand types are 'Point' and 'int')
11 | std::cout << std::boolalpha << (a == 2) << "\n";
| ~ ^~ ~
| | |
| | int
| Point
diff-type.cpp:6:10: note: candidate: 'bool Point::operator==(const Point&) const'
6 | bool operator==(const Point&) const = default;
| ^~~~~~~~
diff-type.cpp:6:21: note: no known conversion for argument 1 from 'int' to 'const Point&'
6 | bool operator==(const Point&) const = default;
| ^~~~~~~~~~~~
The note under the error is the useful part. GCC found the candidate this time and rejected it for a stated reason: there is no known conversion from int to const Point&. When the operand types in the title error differ, read the notes before touching the type. Either the comparison itself is a mistake, and the right-hand side should be a Point, or the type genuinely needs a second operator== that accepts the other type. Adding that second operator is a design decision about what it means for a Point to equal a number, not a mechanical repair.
Comparing pointers is not comparing objects
One nearby form compiles with no operator== anywhere, and it is a trap precisely because it compiles:
#include <iostream>
struct Point {
int x;
int y;
};
int main() {
Point a{1, 2};
Point b{1, 2};
Point* pa = &a;
Point* pb = &b;
std::cout << std::boolalpha
<< (pa == pb) << "\n"
<< (pa == &a) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o pointers pointers.cpp
$ ./pointers
false
true
Point has no operator== in this program, and no error appears, because pa and pb are pointers, and pointers have a built-in equality comparison: two pointers compare equal when they point to the same object. a and b hold identical members, yet pa == pb prints false, because they are different objects at different addresses. pa == &a prints true for the same reason. When a comparison compiles but answers false for objects that look equal, check whether the operands are pointers. Dereferencing them, pa == pb, compares the objects, and that is the form that needs the operator this guide adds.
Defining only operator!= does not fix ==
In C++20 the two equality operators are linked, but the link runs one way: != is answered through ==, not the reverse. A type that defines only operator!= still has no ==:
#include <iostream>
struct Point {
int x;
int y;
bool operator!=(const Point& other) const {
return x != other.x || y != other.y;
}
};
int main() {
Point a{1, 2};
Point b{1, 2};
std::cout << std::boolalpha << (a == b) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o neq-only neq-only.cpp
neq-only.cpp: In function 'int main()':
neq-only.cpp:14:39: error: no match for 'operator==' (operand types are 'Point' and 'Point')
14 | std::cout << std::boolalpha << (a == b) << "\n";
| ~ ^~ ~
| | |
| | Point
| Point
The error is the title error, unchanged, even though a hand-written operator!= sits in the class. == is the primary operator of the pair. Code that needs both should define == and let != follow it, which the next sections show, rather than defining != and expecting == to follow.
What != does in C++20, and what it did before
Before C++20, == and != were separate operators in practice: a class that defined only operator== had no !=, and using != drew its own no-match error. This program defines only a hand-written operator== and then uses !=:
#include <iostream>
struct Point {
int x;
int y;
bool operator==(const Point& other) const {
return x == other.x && y == other.y;
}
};
int main() {
Point a{1, 2};
Point c{1, 3};
std::cout << std::boolalpha << (a != c) << "\n";
return 0;
}
Compiled as C++17, it fails:
$ g++ -std=c++17 -g -o neq17 neq.cpp
neq.cpp: In function 'int main()':
neq.cpp:14:39: error: no match for 'operator!=' (operand types are 'Point' and 'Point')
14 | std::cout << std::boolalpha << (a != c) << "\n";
| ~ ^~ ~
| | |
| | Point
| Point
The same file, compiled as C++20, builds and runs:
$ g++ -std=c++20 -g -o neq neq.cpp
$ ./neq
true
Nothing in the source changed. In C++20, an expression of the form a != b is rewritten in terms of == when no suitable operator!= is found: the compiler considers a rewritten candidate that answers !(a == b). That is why the fixes below define no operator!= at all and still leave both == and != working in C++20, and why code that must also build as C++17 needs its own operator!= written out next to operator==.
Fix one: default operator== in C++20
When member-by-member equality is the right rule and the code builds as C++20, one line inside the class is the whole fix:
#include <iostream>
struct Point {
int x;
int y;
bool operator==(const Point&) const = default;
};
int main() {
Point a{1, 2};
Point b{1, 2};
Point c{1, 3};
std::cout << std::boolalpha
<< (a == b) << "\n"
<< (a == c) << "\n"
<< (a != c) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o defaulted defaulted.cpp
$ ./defaulted
true
false
true
The defaulted operator compares corresponding members in declaration order, x first, then y, and stops at the first member pair that compares unequal. a == b is true because both members match; a == c is false because y differs. The third line, a != c, works without any operator!= in the class, through the rewriting described above. The return type of a defaulted operator== is bool, and the function is const, as the declaration shows: a comparison that modified either object would not be callable on the const references and values this operator is normally used with.
The defaulted form is C++20 only. The same declaration compiled as C++17 is rejected before main is even reached:
$ g++ -std=c++17 -g -o def17 defaulted.cpp
defaulted.cpp:6:10: error: defaulted 'bool Point::operator==(const Point&) const' only available with '-std=c++20' or '-std=gnu++20'
6 | bool operator==(const Point&) const = default;
| ^~~~~~~~
defaulted.cpp: In function 'int main()':
defaulted.cpp:16:21: error: no match for 'operator!=' (operand types are 'Point' and 'Point')
16 | << (a != c) << "\n";
| ~ ^~ ~
| | |
| | Point
| Point
A project pinned to an earlier standard uses fix two instead. A project free to move to C++20 gets this fix and the automatic != together.
When the defaulted operator is itself deleted
Defaulting is a request the compiler can only honor if every member can be compared. Give Point a member whose type has no operator==, wrap it in a type that defaults its own operator==, and the defaulted operator is defined as deleted:
#include <iostream>
struct Inner {
int v;
};
struct Outer {
Inner inner;
bool operator==(const Outer&) const = default;
};
int main() {
Outer a{1};
Outer b{1};
std::cout << std::boolalpha << (a == b) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o member-no-eq member-no-eq.cpp
member-no-eq.cpp: In function 'int main()':
member-no-eq.cpp:15:42: error: use of deleted function 'constexpr bool Outer::operator==(const Outer&) const'
15 | std::cout << std::boolalpha << (a == b) << "\n";
| ^
member-no-eq.cpp:9:10: note: 'constexpr bool Outer::operator==(const Outer&) const' is implicitly deleted because the default definition would be ill-formed:
9 | bool operator==(const Outer&) const = default;
| ^~~~~~~~
member-no-eq.cpp:8:11: error: no match for 'operator==' (operand types are 'Inner' and 'Inner')
8 | Inner inner;
| ^~~~~
The wording changes from no match to use of deleted function, and the last error line names the real gap: Inner and Inner, one level down. The repair runs in the same direction. Add an operator== to Inner, defaulted or hand-written, and Outer's defaulted operator has a usable candidate for its only member. Until then, Outer's defaulted comparison cannot be used, in either the == or the != form.
Fix two: write operator== by hand
A hand-written operator states the equality rule directly, member by member. It is the fix for code that must build before C++20, and for types where equality is not simply all members equal, such as a type that should ignore a cached member or compare an identifier member only:
#include <iostream>
struct Point {
int x;
int y;
bool operator==(const Point& other) const {
return x == other.x && y == other.y;
}
};
int main() {
Point a{1, 2};
Point b{1, 2};
Point c{1, 3};
std::cout << std::boolalpha
<< (a == b) << "\n"
<< (a == c) << "\n";
return 0;
}
$ g++ -std=c++20 -g -o handwritten handwritten.cpp
$ ./handwritten
true
false
The same file also builds and runs unchanged as C++17:
$ g++ -std=c++17 -g -o hand17 handwritten.cpp
$ ./hand17
true
false
The body compares x, then y, and the && short-circuits on the first mismatch, matching the order the defaulted operator would use for this class. Two details in the declaration carry the weight. The parameter is a const reference, so comparing does not copy the other object and works when the other object is const. The trailing const makes the function callable on a const Point, which is the common case at real call sites. In C++20 this hand-written operator also serves != through rewriting, as the earlier section showed. In C++17 it serves == only, so a C++17 codebase that uses != adds a hand-written operator!= beside it that returns the negation of ==.
The cases, in short
| Case | Operands | Result |
|---|---|---|
| No operator== declared | Point, Point | Title error |
| Operator== takes Point only | Point, int | Title error |
| Pointers, no operator== | Point, Point | Address comparison |
| Only operator!= declared | Point, Point | Title error |
| Defaulted, member lacks == | Outer, Outer | Deleted function error |
| Hand-written ==, != in C++17 | Point, Point | No match for != |
| Hand-written ==, != in C++20 | Point, Point | Works, rewritten |
The fixes, ranked
- Default operator== in C++20 when member-by-member equality is the right rule. One line, and != comes with it through rewriting.
- Write operator== by hand when the code must build before C++20, or when equality is not all members equal. In C++17, write operator!= beside it if the code uses !=.
- Never fix this error at the call site by comparing members inline everywhere == is used. One call site may read clearly; every later call site repeats the rule, and the copies drift. The operator is where the rule belongs.
Checklist
- Read the operand types in the first error line: same type on both sides means the operator is missing; different types mean the existing operator does not accept that pairing.
- Read the notes under the error: a rejected candidate states the conversion that failed.
- Check for pointers before adding anything: pointer equality already compiles and compares addresses.
- Define ==, not only !=: in C++20, != is answered through ==, never the reverse.
- After defaulting, follow a deleted-function error down one level: the member named in the last error line needs its own operator==.
- If the code must build as C++17, skip the defaulted form and write both operators by hand where both are used.
Related guides
- C++20 Spaceship Operator — the three-way comparison operator, which can also supply equality when it is defaulted alongside or instead of operator==.
- No Match for Operator<< Fix — the same no-match wording for stream insertion, fixed by declaring the operator the search failed to find.
- C++ Classes and Objects — the class basics behind this guide: members, member functions, and const member functions such as the operators declared here.
Sources
- cppreference, Default comparisons — a defaulted operator== has return type bool, compares corresponding base and member subobjects in declaration order, stops at the first unequal subobject, and is defined as deleted when a subobject comparison has no usable candidate.
- cppreference, Comparison operators — the equality operator expressions, the built-in pointer equality rules, and the C++20 rewritten candidates that let != be answered through ==.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.