Connecting Tech Pros Worldwide Help | Site Map

'operator >>' is ambiguous

John M
Guest
 
Posts: n/a
#1: Jul 22 '05
Can someone tell how to fix my visual c++ so it can discard this error
message.
I get this error message
error C2593: 'operator >>' is ambiguous
But I do not when I am on my mandrake linux platform. Why is this, a bug in
visual c++ ?

John J


David Harmon
Guest
 
Posts: n/a
#2: Jul 22 '05

re: 'operator >>' is ambiguous


On Sat, 19 Jun 2004 19:41:33 -0400 in comp.lang.c++, "John M"
<jj1100@hotmail.com> wrote,[color=blue]
>Can someone tell how to fix my visual c++ so it can discard this error
>message.
>I get this error message
> error C2593: 'operator >>' is ambiguous
>But I do not when I am on my mandrake linux platform. Why is this, a bug in
>visual c++ ?[/color]

Possibly a bug in VC++. Possibly a bug in g++.
How the heck could anybody guess when your code is secret?

John Harrison
Guest
 
Posts: n/a
#3: Jul 22 '05

re: 'operator >>' is ambiguous



"John M" <jj1100@hotmail.com> wrote in message
news:Na4Bc.320$s01.3850@news20.bellglobal.com...[color=blue]
> Can someone tell how to fix my visual c++ so it can discard this error
> message.
> I get this error message
> error C2593: 'operator >>' is ambiguous
> But I do not when I am on my mandrake linux platform. Why is this, a bug[/color]
in[color=blue]
> visual c++ ?
>
> John J
>[/color]

Post the code!!

My guess is that you are mixing correct headers (like <string>) with
incorrect headers (like <iostream.h>). In other words your code is at fault
not g++, or VC++. No C++ headers (except those that C++ gets from C) have a
..h

#include <iostream.h> // wrong
#include <iostream> // right

#include <fstream.h> // wrong
#include <fstream> // right

#include <string.h> // OK, C string handling
#include <string> // OK, C++ string handling

Gosh my psychic powers are good today.

john


Ayaz Ahmed Khan
Guest
 
Posts: n/a
#4: Jul 22 '05

re: 'operator >>' is ambiguous


"John M" typed:
[color=blue]
> Can someone tell how to fix my visual c++ so it can discard this
> error message.
> I get this error message
> error C2593: 'operator >>' is ambiguous
> But I do not when I am on my mandrake linux platform. Why is this, a
> bug in visual c++ ?[/color]


I think it's a bug in VC++/6.0, though I may be wrong. I overloaded
the insertion operator for my own class, Questions, once. I placed a
number of such objects in a "list" container, declared an iterator,
moved it to point to the object that I wanted it to, dereferenced it,
and called

cout << *iter;

g++ didn't complain. VC++/6.0 flagged it as ambiguous.

--
Ayaz Ahmed Khan

"I don't trust him. We're friends". -- Bertolt Brecht

John M
Guest
 
Posts: n/a
#5: Jul 22 '05

re: 'operator >>' is ambiguous


[color=blue]
> Post the code!![/color]

#include <iostream>
#include<conio.h>
using namespace std;

class Equipment {
protected:
float price;

public:
Equipment(float p)
{ price = p;}

virtual void display() const { }
virtual void read() { }
} ;

class Printer : public Equipment {
private:
char* type;
int speed;

public:
Printer(const char s[] = "", const float p = 0, const int ppm = 0) :
Equipment(p)
{ type = new char[strlen(s)+1];
if (type == NULL) { cout << "Out of memory\n"; exit(0); }
strcpy(type,s);
speed = ppm;}

friend ostream& operator << (ostream& out, const Equipment* e);
friend istream& operator >> (istream& in, Equipment& e);

/*Printer& operator = (const Printer& p)
{ if (this == &p) return *this;
delete [] type;
strcpy(type, p.type);
return *this; } */

void read()
{ cout << " Enter printer type : "; cin >> type;
cout << " Enter printer speed: "; cin >> speed;
cout << " Enter printer price: "; cin >> price;
cout << endl;}

void display() const
{ cout << " Printer type: " << type << endl;
cout << " Printer speed: " << speed << endl;
cout << " Printer price: " << price << endl << endl; }

~Printer()
{ delete [] type; }
} ;



ostream& operator << (ostream& out, const Equipment* e) //for cout
{ e->display(); return out;}

istream& operator >> (istream& in, Equipment& e) // for cin
{ e.read(); return cin;}

int main()
{ cout << endl << endl;
Equipment* dataBase[10]; int cnt = 0;

Printer p;

cout << " --- Reading Objects --- " << endl;
cin >> p;
dataBase[cnt++] = &p;


cout << " --- Displaying Objects --- " << endl;
for (int i=0; i < cnt; i++)
cout << dataBase[i];
getch();
return 0;

}






[color=blue]
>
> My guess is that you are mixing correct headers (like <string>) with
> incorrect headers (like <iostream.h>). In other words your code is at[/color]
fault[color=blue]
> not g++, or VC++. No C++ headers (except those that C++ gets from C) have[/color]
a[color=blue]
> .h
>
> #include <iostream.h> // wrong
> #include <iostream> // right
>
> #include <fstream.h> // wrong
> #include <fstream> // right
>
> #include <string.h> // OK, C string handling
> #include <string> // OK, C++ string handling
>
> Gosh my psychic powers are good today.
>
> john
>
>[/color]


John Harrison
Guest
 
Posts: n/a
#6: Jul 22 '05

re: 'operator >>' is ambiguous



"John M" <jj1100@hotmail.com> wrote in message
news:HDABc.12$Es5.236@news20.bellglobal.com...[color=blue]
>[color=green]
> > Post the code!![/color]
>
> #include <iostream>
> #include<conio.h>
> using namespace std;
>
> class Equipment {
> protected:
> float price;
>
> public:
> Equipment(float p)
> { price = p;}
>
> virtual void display() const { }
> virtual void read() { }
> } ;
>
> class Printer : public Equipment {
> private:
> char* type;
> int speed;
>
> public:
> Printer(const char s[] = "", const float p = 0, const int ppm = 0) :
> Equipment(p)
> { type = new char[strlen(s)+1];
> if (type == NULL) { cout << "Out of memory\n"; exit(0); }
> strcpy(type,s);
> speed = ppm;}
>
> friend ostream& operator << (ostream& out, const Equipment* e);
> friend istream& operator >> (istream& in, Equipment& e);
>
> /*Printer& operator = (const Printer& p)
> { if (this == &p) return *this;
> delete [] type;
> strcpy(type, p.type);
> return *this; } */
>
> void read()
> { cout << " Enter printer type : "; cin >> type;
> cout << " Enter printer speed: "; cin >> speed;
> cout << " Enter printer price: "; cin >> price;
> cout << endl;}
>
> void display() const
> { cout << " Printer type: " << type << endl;
> cout << " Printer speed: " << speed << endl;
> cout << " Printer price: " << price << endl << endl; }
>
> ~Printer()
> { delete [] type; }
> } ;
>
>
>
> ostream& operator << (ostream& out, const Equipment* e) //for cout
> { e->display(); return out;}
>
> istream& operator >> (istream& in, Equipment& e) // for cin
> { e.read(); return cin;}
>
> int main()
> { cout << endl << endl;
> Equipment* dataBase[10]; int cnt = 0;
>
> Printer p;
>
> cout << " --- Reading Objects --- " << endl;
> cin >> p;
> dataBase[cnt++] = &p;
>
>
> cout << " --- Displaying Objects --- " << endl;
> for (int i=0; i < cnt; i++)
> cout << dataBase[i];
> getch();
> return 0;
>
> }
>[/color]

It compiles without problems on my VC++ 6.

I can see a few issues with the code but nothing that would cause it to fail
to compile.

Maybe you don't have the latest service pack for the compiler, or maybe your
installation or project settings are incorrect. Whatever it is it not a C++
issue, try a VC++ 6 group, e.g. news:microsoft.public.vc.ide_general.

john


Prateek R Karandikar
Guest
 
Posts: n/a
#7: Jul 22 '05

re: 'operator >>' is ambiguous


"John M" <jj1100@hotmail.com> wrote in message news:<HDABc.12$Es5.236@news20.bellglobal.com>...[color=blue][color=green]
> > Post the code!![/color]
>
> #include <iostream>
> #include<conio.h>[/color]

"conio.h"??? There is no such standard header.

-- --
To iterate is human, to recurse divine.
-L. Peter Deutsch
-- --
Richard Herring
Guest
 
Posts: n/a
#8: Jul 22 '05

re: 'operator >>' is ambiguous


In message <2jo4hrF11jkfjU1@uni-berlin.de>, John Harrison
<john_andronicus@hotmail.com> writes[color=blue]
>
>"John M" <jj1100@hotmail.com> wrote in message
>news:HDABc.12$Es5.236@news20.bellglobal.com...[color=green]
>>[color=darkred]
>> > Post the code!![/color]
>>
>> #include <iostream>
>> #include<conio.h>
>> using namespace std;[/color][/color]

[snip][color=blue]
>
>It compiles without problems on my VC++ 6.
>
>I can see a few issues with the code but nothing that would cause it to fail
>to compile.
>[/color]
There's no guarantee that <iostream> includes <istream>, which is where
the overloads for operator>> are actually declared. Add <istream> (and
<ostream>) and see what happens.

--
Richard Herring
Closed Thread