'operator >>' is ambiguous

J

John M

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
 
D

David Harmon

On Sat, 19 Jun 2004 19:41:33 -0400 in comp.lang.c++, "John M"
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++ ?

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

John Harrison

John M said:
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

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
 
A

Ayaz Ahmed Khan

"John M" typed:
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++ ?


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

John M

Post the code!!

#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;
getch();
return 0;

}
 
J

John Harrison

John M said:
Post the code!!

#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;
getch();
return 0;

}


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.
john
 
P

Prateek R Karandikar

John M said:
#include <iostream>
#include<conio.h>

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

-- --
To iterate is human, to recurse divine.
-L. Peter Deutsch
-- --
 
R

Richard Herring

John Harrison said:
John M said:
#include <iostream>
#include<conio.h>
using namespace std;
[snip]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top