This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


It seems weird to me that this would have compiled before.  Surely you
can't write to pal.used when pal is const?

Brian

On 6/18/06, Andrew McLean <am611@tiscali.co.uk> wrote:
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.

---------------
{
...
private:
...
     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 >>
pal->Palette::used'

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.

AM




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]