#include <iostream>
usingnamespace std; // for this experiment
int main() {
operator<<(cout, 42);
// ambiguous overload error; candidates offer char,
// signed char, and unsigned char for the second
// parameter.
// Apparently you can only pass a char, a c-string
// or a std::string for the second parameter.
// But then why can you do this?
cout << 42;
}
operator<<(std::cout, 42); is not equivalent to std::cout << 42;, it's equivalent to std::cout.operator<<(42);
Line 5 uses Argument-Dependent Lookup (ADL), which finds multiple, ambiguous candidates.
(Note: All credit to Sombrero Chicken and Remy Lebeau, I had no idea why that happened before reading it.)