Reputation: 1554
Here is the simple code :
int main()
{
int x=0;
std::cout<<x;
operator<<(std::cout,x); //ambiguous
return 0;
}
Why is the operator<<(std::cout,x)
call ambiguous but not std::cout<<x;
? Thanks
Upvotes: 2
Views: 223
Reputation: 409136
The problem here is that for outputting integers, operator<<
is an std::ostream
member function.
So to explicitly call the operator function you should do e.g.
std::cout.operator<<(x);
The stand-alone operator<<
function is for characters and strings.
Upvotes: 6