In C++ language operator <
makes the compiler to consider a built-in candidate function of the form
bool operator<(T, T);
for every possible pointer type T
. In particular, that means that there's such a function for void *
type. This is the function that is applicable in your case. String literal is implicitly convertible to void *
and std::cout
is also implicitly convertible to void *
.
You can reproduce the same behavior with the following minimalist example
struct X {
operator void *() { return 0; }
};
int main() {
X() < "";
}
The above would apply to C++03. I'm not sure why it compiles in C+11 tough (assuming it does), since in C++11 stream conversion to void *
was replaced with explicit conversion to bool
.