473,803 Members | 3,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'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 9191
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.b ellglobal.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_g eneral.

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
3217
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
2055
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 fine? // --------- foo.cpp --------- #include <iostream> using namespace std;
4
2484
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 templatized operator>>() as a member that can deal with the built in C types (int, char, float...) template <class tType> STR& STR::operator>>(tType & t); I then attempted to add an overloaded version of this to support my own
2
12908
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
1684
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
2064
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
2815
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
2941
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 raw pointer at "the end of the arrow". For types that support the operator, I have a reasonable solution, but I'd like to have a null pointer returned if the operator isn't supported by a particular object.
6
1936
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
9565
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.