Error message for 'ambiguous overload for operator>>' in gcc 4.1.0

Andrew McLean
Sun Jun 18 23:34:00 GMT 2006

I have program that builds and runs OK when using gcc 3.3.5, but gets an
error when built with gcc 4.1.0.  For now, I'll just pick out what seem
to be the salient fragments...

palette.h  Class definitions etc.
The Class 'palette' includes the following fragment:
'...' indicates other lines omitted for clarity.

     long used;

palette.cpp   Member functions etc.
This file includes code sections ('functors' ?) to overload the '>>' and
'<<' operators. These allow 'palette' objects to be written to and read
back from a simple text file.
One such section includes the following:

std::istream &operator >> (std::istream &str, const Palette &pal)
  str >> pal.used;      [*** error here]
   return str;

With gcc 4.1.0, the line marked 'error here' generates this error message:

palette.cpp:204: error: ambiguous overload for 'operator>>' in 'str >>

and it then lists four alternative definitions for '>>' from the
'istream' file, which it can't choose between.

I found I could kludge the problem by making 'used' an array, and just
using the first element.

The obvious questions are:
1. What is the 'best' way to clear this error ?
2. What changed in gcc 4.x to trigger this problem ? I had a quick trawl
through the gcc website but didn't spot anything that looked relevant.


More information about the Gcc-help mailing list