C++: error: no match for 'operator<<' (operand types are 'std::ostream' and 'X')
You used an operator on a type that does not define it — most often printing your own class with << or comparing two objects.
no match for 'operator<<'no match for 'operator=='no match for 'operator<'no match for call tocandidate: operator<< Meaning
C++ does not generate operator<<, == or < for your classes. The long list of "candidate" overloads that follows the message shows the closest built-in matches; none accept your type. Provide the operator as a free function (or member) and make sure it is visible where you use it.
Common causes
- Class has no
operator<<for std::ostream - Class has no operator== / operator< (needed by std::find, std::sort, std::map)
- Operator declared in another namespace, so ADL cannot find it
- const mismatch: operator takes a non-const reference
- Missing
#include <iostream>/<string>
⚡ Quick fix
- Define the operator for your type
- Put the operator in the same namespace as the class
- Take parameters by const reference
Detailed fix by platform
C++
- Declare
std::ostream& operator<<(std::ostream& os, const Point& p);next to the class - In C++20 you can write
bool operator==(const Point&) const = default;orauto operator<=>(const Point&) const = default;
Code examples
Teach std::cout to print a class
#include <iostream>
struct Point { int x, y; };
std::ostream& operator<<(std::ostream& os, const Point& p) {
return os << "(" << p.x << ", " << p.y << ")";
}
int main() {
Point p{1, 2};
std::cout << p << "\n"; // prints (1, 2)
}How to diagnose
- Types — Operand types in the message?
- Namespace — Is the operator in the class's namespace?
- Const — Does the signature use const T&?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- cannot declare variable to be of abstract type C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions)
- discards qualifiers C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive]
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026