public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Error message for 'ambiguous overload for operator>>' in gcc 4.1.0
@ 2006-06-19 16:25 am611
  0 siblings, 0 replies; 3+ messages in thread
From: am611 @ 2006-06-19 16:25 UTC (permalink / raw)
  To: gcc-help

Thanks for the various comments; my conclusions:
- The problem was caused by erroneous use of 'const'. Now resolved.
- The same error msg does occur in gcc 3.3.5, but in my case had been masked
by a (long) cast
   e.g. the line
   str >> (long) pal.used;
   does not get flagged as an error.
- It would have been easier to solve if the error message had flagged the
incorrect use of 'const'.
I must gen up on 'const' a bit...

AM


___________________________________________________________

Tiscali Broadband from 14.99 with free setup!
http://www.tiscali.co.uk/products/broadband/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Error message for 'ambiguous overload for operator>>' in gcc 4.1.0
  2006-06-18 23:34 Andrew McLean
@ 2006-06-19 15:40 ` Brian Budge
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Budge @ 2006-06-19 15:40 UTC (permalink / raw)
  To: Andrew McLean; +Cc: gcc-help

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
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Error message for 'ambiguous overload for operator>>' in gcc 4.1.0
@ 2006-06-18 23:34 Andrew McLean
  2006-06-19 15:40 ` Brian Budge
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew McLean @ 2006-06-18 23:34 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-19 16:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-19 16:25 Error message for 'ambiguous overload for operator>>' in gcc 4.1.0 am611
  -- strict thread matches above, loose matches on Subject: below --
2006-06-18 23:34 Andrew McLean
2006-06-19 15:40 ` Brian Budge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).