473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C2593: 'operator <<' is ambiguous

rjd
Does anybody else see this in VS.NET 2003?

When I get a genuine C++ compiler error (could be anything, usually
innocuous) it's regularly followed by a slew of these spurious and completely
unrelated ones:

error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\ostream(697): could be 'std::basic_ostream<_Elem,_Traits>
&std::operator <<<std::char_traits<char>>(std::basic_ostream<_Ele m,_Traits>
&,const char *)' [found using argument-dependent lookup]
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits>
&std::operator <<<std::char_traits<char>>(std::basic_ostream<_Ele m,_Traits>
&,const char *)' [found using argument-dependent lookup]
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::ostream, const char
[4])'

There's probably one of these for every use of operator<< in the file, but
I've never bothered to check that; there are just lots. Note that where it
says "could be X or Y", X and Y are identical! There's nothing obviously
wrong with the use of these operators, and if I fix the real error the
spurious ones disappear.

If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.

Rob
Nov 17 '05 #1
4 3224
rjd wrote:
Does anybody else see this in VS.NET 2003? If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.


Can you post a short test case that triggers the errors?

Tom
Nov 17 '05 #2
rjd
It took me a while to work this out but it's worth it because it's suggested
a work-around. Here's the example:

------
#include <iostream>

using std::operator<<;

int main(int argc, char* argv[]) {
int x = f();
std::cout << "Hello" << std::endl;
}
------

There's a genuine error here at f() but that's followed by a spurious error
at the first <<. Delete the declaration of x and it compiles OK.

The culprit, if you haven't guessed already, is the using declaration for
operator<<. Remove that and the extra error disappears. It's unnecessary in
this case, and in many cases, because of argument-dependent lookup; I'll have
to experiment to see whether I can remove it generally from our code (we've
needed it in the past, given the range of compilers and platforms we build
on).

Rob
------
"Tom Widmer [VC++ MVP]" wrote:
rjd wrote:
Does anybody else see this in VS.NET 2003?

If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.


Can you post a short test case that triggers the errors?

Tom

Nov 17 '05 #3
rjd wrote:
It took me a while to work this out but it's worth it because it's suggested
a work-around. Here's the example:

------
#include <iostream>

using std::operator<<;

int main(int argc, char* argv[]) {
int x = f();
std::cout << "Hello" << std::endl;
}
Unrelated to the bug, the above code is non-conforming (even with the
f() bit removed) - you need to
#include <ostream>
in order to use std::endl and non-members of basic_ostream, such as the
<< char const* overload that you are trying to call.
There's a genuine error here at f() but that's followed by a spurious error
at the first <<. Delete the declaration of x and it compiles OK.

The culprit, if you haven't guessed already, is the using declaration for
operator<<. Remove that and the extra error disappears. It's unnecessary in
this case, and in many cases, because of argument-dependent lookup; I'll have
to experiment to see whether I can remove it generally from our code (we've
needed it in the past, given the range of compilers and platforms we build
on).


I've confirmed the bug in VC7.1, but I don't have a VC8 beta installed
to see whether it has been fixed. Anyone?

Tom
Nov 17 '05 #4
rjd <rj*@discussions.microsoft.com> wrote:
[...]
If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.
I know this, too, although I get it for other
stuff. In some of my files, whenever a syntax
error occurs, the compiler just freaks out and
throughs kilobytes of stupid errors at me after
the first one. Templates and overloads seem to
be in the pool of things that trigger this.
I got into the habit of fixing the first error
and just recompile if the next two messages do
not seem to make much sense to me. Yes, it's
annoying and it steals time. But C++ compilers
are hard to write and it's even harder to write
them so that they give good error messages. If
some particular message soesn't make any sense
to you, throw the code at Comeau -- its messages
are excellent (www.comeaucomputing.com/tryitout).
Rob

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: franky.backeljauw | last post by:
Hello, I have a problem with using a copy constructor to convert an object of a templated class to object of another templated class. Let me first include the code (my question is below): ...
5
by: Gianni Mariani | last post by:
Can anyone enligten me why I get the "ambiguous overload" error from the code below: friendop.cpp: In function `int main()': friendop.cpp:36: ambiguous overload for `std::basic_ostream<char,...
3
by: Alex Vinokur | last post by:
Member operators operator>>() and operator<<() in a program below work fine, but look strange. Is it possible to define member operators operator>>() and operator<<() that work fine and look...
3
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD...
14
by: lutorm | last post by:
Hi everyone, I'm trying to use istream_iterators to read a file consisting of pairs of numbers. To do this, I wrote the following: #include <fstream> #include <vector> #include <iterator> ...
4
by: bluekite2000 | last post by:
Here A is an instantiation of class Matrix. This means whenever user writes Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2 //and fills it up w/ random value cout<<A; the...
25
by: Steve Richter | last post by:
is it possible to overload the << operator in c# similar to the way it is done in c++ ? MyTable table = new MyTable( ) ; MyTableRow row = new MyTableRow( ) ; row << new MyTableCell( "cell1 text...
7
by: glen | last post by:
Hi. I'm using GCC 4.1.1, which I mention since I don't know if this is a compiler issue, or me not understanding some subtlety in the standard. The code below compiles fine under vc++, but I'm...
4
by: aaragon | last post by:
Hi everyone, I was unable to find out why my code is not compiling. I have a template class and I'm trying to write the operator<< for standard output. Does anyone know why this is not right?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.