overloading operator<< for arrays overloading operator<< for arrays arrays arrays

overloading operator<< for arrays


The first stage of overload resolution is to identify the viable functions, which are those which can accept the number of arguments provided (completely ignoring types). (See eg 13.3.2 [over.match.viable]).

Then any needed conversions are considered to determine which is the unique best viable function.

In this case there is no such unique best (there's two equally good candidates).

The error message could just tell you the two ambiguous cases. But I think they're trying to be helpful by showing why all the other viable functions lost out. Sometimes this is useful, when you can't figure out why the function you wanted to be called hasn't been considered.

But I agree that mostly it's just a lot of noise, especially for functions like operator << or operator >> (or even operator []) which have a lot of overloads.


The compiler is correct to reject the program. I think the key is that your overload and ostream::operator<<( char const * ) both appear in the error message. The integral ones are probably a red herring… you can reinterpret_cast a pointer (or a string literal) to long int (§5.2.10/4), but that's certainly not a standard conversion. Perhaps the compiler is just trying to be helpful by giving you more overloads.

Given your overload and the ostream member, overload resolution fails simply because there is no precedence rule to decide between them (§13.3.1.2). So, because the char const * member overload is the only one you might conflict with, your fix does seem appropriate.