GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Nov-2004, 14:49
Krc784 Krc784 is offline
New Member
 
Join Date: Nov 2004
Posts: 9
Krc784 is on a distinguished road

Ambiguous operator


I have a build error that says operator << is ambiguous what does it mean by saying to ambiguous??

here is the code i have in that specific line

cout << fixed << showpoint << setprecision(2);
  #2  
Old 04-Nov-2004, 14:59
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Krc784
I have a build error that says operator << is ambiguous what does it mean by saying to ambiguous??

here is the code i have in that specific line

cout << fixed << showpoint << setprecision(2);

You may have to indicate that you are using cout from the std namespace.

Don't know what I mean? Lots of older books (and some current ones) and lots of tutorials don't mention this because pre-standard C++ didn't have such things.

Nowadays, your program should look something like:

CPP / C++ / C Code:
#include <iostream>
using namespace std;
int main()
{
  cout << "Hi, there" << endl;
  return 0;
}

Later, when you learn about namespaces, you may want to do it differently, but for now you can consider the "using namespace std;" to be an idiom: just do it.

Regards,

Dave
  #3  
Old 04-Nov-2004, 15:03
Krc784 Krc784 is offline
New Member
 
Join Date: Nov 2004
Posts: 9
Krc784 is on a distinguished road

reply to ambigious operator


i know the namesspace std; thing and i have it at the top and its still telling me that in that one line for some reason in that same code
  #4  
Old 04-Nov-2004, 15:26
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Krc784
i know the namesspace std; thing and i have it at the top and its still telling me that in that one line for some reason in that same code


How can I guess what your problem is? My first guess didn't help. Maybe you should show us the code???????????????

You might also mention what operating system and what compiler you are using.

Regards,

Dave
  #5  
Old 08-Nov-2004, 02:04
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
The << operator is ambiguous to what you are displaying, which is nothing. You set some flags, but you never display any data. You should probably set the flags and display the data all in one statement. You set the showpoint flag, but to show the point in what number? You set the setprecision flag, but to show 2 points of precision in what number? I am pretty sure that when you set flags, you also have to display something!
__________________
-Aaron
  #6  
Old 08-Nov-2004, 09:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by aaroncohn
The << operator is ambiguous to what you are displaying, which is nothing. You set some flags, but you never display any data. You should probably set the flags and display the data all in one statement. You set the showpoint flag, but to show the point in what number? You set the setprecision flag, but to show 2 points of precision in what number? I am pretty sure that when you set flags, you also have to display something!

Not true. Compile and execute the following:

CPP / C++ / C Code:
#include <iostream>
#include <iomanip>

using namespace std;
int main()
{

  //double x = 123.456;

  //cout << "x = " << x << endl;
  cout << fixed << showpoint << setprecision(2);
  //cout << "x = " << x << endl;

  return 0;
}


What do you get: nothing. (No compile errors, no output from the progam, no hits, no runs, no men left on base. What you don't see is what you don't get.)

Then uncomment the commented lines and run again. What do you get? Just about what you expected, right?

Since the original poster still hasn't shown us what he is trying to do, I don't see how we can guess what his problem is. His problem is not in the line that he abstracted for us.

Hint to all users: when the compiler says there is an error on a particular line and that line looks OK, then you should look at lines before the indicated one.

Hint to all people requestinghelp: show us what you have, what you expected to get and what you got (source code with detailed error messages).

Regards,

Dave
  #7  
Old 08-Nov-2004, 13:43
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 889
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
I am all for your suggestion, Dave, but in this particular case the "error" might be in the line provided by the poster; please take a look at my post here, where I bitch about not being able to use the fixed modifier with some compilers .

However, I think that some info would be appropiate - like the compiler used on the code sample.
I hope this is the annoying "bug" - if not, we'll have to dig deeper

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #8  
Old 08-Nov-2004, 13:49
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by LuciWiz
I am all for your suggestion, Dave, but in this particular case the "error" might be in the line provided by the poster; please take a look at my post here, where I bitch about not being able to use the fixed modifier with some compilers .

However, I think that some info would be appropiate - like the compiler used on the code sample.
I hope this is the annoying "bug" - if not, we'll have to dig deeper

Kind regards,
Luci

You know, it was really wrong of me (and, more than a little, silly) to suggest that the code that I posted would work with every compiler everywhere.

What I should have done was to report that it works with my compilers, and suggest that people who think that there might be problems with this kind of stuff simplify their programs to a single line in main() and see if their compilers complained.

Thanks for helping to set me back on the path to the light.

Regards,

Dave
  #9  
Old 08-Nov-2004, 15:09
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 889
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by davekw7x
You know, it was really wrong of me (and, more than a little, silly) to suggest that the code that I posted would work with every compiler everywhere.

What I should have done was to report that it works with my compilers, and suggest that people who think that there might be problems with this kind of stuff simplify their programs to a single line in main() and see if their compilers complained.

Thanks for helping to set me back on the path to the light.

Regards,

Dave

I wasn't talking about your code, I was talking about the (original) poster's code; he is the one who has a problem which needs solving, not you.
There is no need to get all offensive about this, I guess I didn't make myself clear (as usual)

Quote:
Originally Posted by Krc784
I have a build error that says operator << is ambiguous what does it mean by saying to ambiguous??

here is the code i have in that specific line

cout << fixed << showpoint << setprecision(2);

I was actually backing up your request:

Quote:
Originally Posted by davekw7x
You might also mention what operating system and what compiler you are using.

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #10  
Old 08-Nov-2004, 20:32
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,617
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by LuciWiz
There is no need to get all offensive about this, I guess I didn't make myself clear (as usual)

Regards,
Luci

I didn't think you were being unkind to me; I just wanted to try to let people know that I realize that my previous post was too abrupt and a little snotty. The problem is that it's kind of hard to take back that kind of impression, but I wish I could. Oh, well...


Regards,

Dave
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
or operator Krc784 CPP / C++ Forum 1 04-Nov-2004 14:43
Circular Linked Queue Copy Constructor and Assignment Operator Not Working? wc3promet CPP / C++ Forum 0 17-Oct-2004 07:55
operator overloading hyapici CPP / C++ Forum 2 18-Feb-2004 19:37
char to operator calculus87 CPP / C++ Forum 3 04-Sep-2003 10:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.