473,404 Members | 2,179 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,404 software developers and data experts.

'operator >>' is ambiguous

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
Jul 22 '05 #1
7 9159
On Sat, 19 Jun 2004 19:41:33 -0400 in comp.lang.c++, "John M"
<jj****@hotmail.com> wrote,
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?

Jul 22 '05 #2

"John M" <jj****@hotmail.com> wrote in message
news:Na****************@news20.bellglobal.com...
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
Jul 22 '05 #3
"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.

--
Ayaz Ahmed Khan

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

Jul 22 '05 #4
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[i];
getch();
return 0;

}



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

Jul 22 '05 #5

"John M" <jj****@hotmail.com> wrote in message
news:HD**************@news20.bellglobal.com...
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[i];
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. news:microsoft.public.vc.ide_general.

john
Jul 22 '05 #6
"John M" <jj****@hotmail.com> wrote in message news:<HD**************@news20.bellglobal.com>...
Post the code!!


#include <iostream>
#include<conio.h>


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

-- --
To iterate is human, to recurse divine.
-L. Peter Deutsch
-- --
Jul 22 '05 #7
In message <2j*************@uni-berlin.de>, John Harrison
<jo*************@hotmail.com> writes

"John M" <jj****@hotmail.com> wrote in message
news:HD**************@news20.bellglobal.com...
> Post the code!!
#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.

--
Richard Herring
Jul 22 '05 #8

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

Similar topics

6
by: David Briggs | last post by:
I am using MS VC++ 6.0 with MFC I have a simple class: #include <fstream.h> class Data { public: CString WriteStr(); Data();
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...
4
by: hall | last post by:
Hi all. I have run into a problem of overloading a templatized operator>> by a specialized version of it. In short (complete code below), I have written a stream class, STR, which defines a...
2
by: Bill | last post by:
I am trying to convert a Java APP to C# and it appears C# does not have a >>> operator. Does anyone the best way to conver this operator in to c#? Thanks. -- Bill
2
by: Zorro | last post by:
In header file istream there is an overload for every built-in type, except char. Is there a reason for this? GCC 3.3.4. is the compiler. Thanks.
11
by: Noah Roberts | last post by:
template < typename T > std::istream & operator >(std::istream & in, std::pair<T,T& p) { in >p.first >p.second; return in; } .... std::istream_iterator< std::pair<size_type, size_type
14
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
6
by: edd | last post by:
Hello all, Is there a way to determine whether a particular type supports the -> operator at compile time? I'm trying to write a template function (or a series of overloads) that will yield the...
6
by: puzzlecracker | last post by:
Say we have this structure: Struct Foo{ .... friend ostream& operator << (ostream& s, Foo & m); ..... }; friend ostream& operator << (ostream& s, Foo & m){
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.