Jump to content

  • Log In with Google      Sign In   
  • Create Account


String is ambiguous


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Crusable   Members   -  Reputation: 592

Like
0Likes
Like

Posted 19 November 2012 - 08:59 PM

I am prototyping something for a big project, but i got a funny error saying that string is ambiguous I have never seen this before, and i have been writing my code this way for forever.

[source lang="cpp"]#include "stdafx.h"#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std; class Creature{public: Creature(int strength, int health, int armor, string name); --string error void getHealth(); int modifyHealth(int modifier, int type); //type = 1(add), or 2(remove) int attack(); int block();private: int m_Strength; int m_Health; int m_Damage; int m_Armor; string m_Name; --string error int num;};[/source]

"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


Sponsor:

#2 ultramailman   Prime Members   -  Reputation: 1563

Like
1Likes
Like

Posted 19 November 2012 - 09:08 PM

I think you should take away the
using namespace std;

and use
std::string

instead of
string

But I found that on google's first result. Perhaps you didn't <search engine of choice> hard enough?

Edited by ultramailman, 20 November 2012 - 01:06 AM.


#3 Crusable   Members   -  Reputation: 592

Like
0Likes
Like

Posted 19 November 2012 - 09:33 PM

i always come here first. I diid try that and it didnt work

"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


#4 ultramailman   Prime Members   -  Reputation: 1563

Like
-1Likes
Like

Posted 19 November 2012 - 09:37 PM

That doesn't work? Then how about removing
#include <string>

Because usually iostream also includes string.

#5 Cornstalks   Crossbones+   -  Reputation: 6974

Like
4Likes
Like

Posted 19 November 2012 - 09:44 PM

That doesn't work? Then how about removing

#include <string>

Because usually iostream also includes string.

Don't do that. You should explicitly include the headers you need. But you're absolutely right about using namespace std;. A global using namespace ...; should never go in a header.

@OP: You should always Google first. It's a fantastic skill to learn. What are your other headers/sources doing? Is anything defining string before your header? Anything in stdafx.h? Typically it's caused by something like this example.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 SiCrane   Moderators   -  Reputation: 9575

Like
1Likes
Like

Posted 19 November 2012 - 09:50 PM

It looks like you're using MSVC from the stdafx.h in your headers. If that's the case, then you might want to look at the full build output rather than the summary in the task pane. It will probably tell you the exact source of the ambiguous symbols.

#7 ultramailman   Prime Members   -  Reputation: 1563

Like
0Likes
Like

Posted 19 November 2012 - 09:51 PM

Don't do that. You should explicitly include the headers you need


True, I just thought that might be a last resort that magically fixes OP's problem. It's improbable, but I thought maybe his string header doesn't have include guards.

#8 Bacterius   Crossbones+   -  Reputation: 8694

Like
0Likes
Like

Posted 19 November 2012 - 10:16 PM


Don't do that. You should explicitly include the headers you need


True, I just thought that might be a last resort that magically fixes OP's problem. It's improbable, but I thought maybe his string header doesn't have include guards.

I would expect the OP to have bigger problems if his standard headers don't have include guards though :)

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#9 Khatharr   Crossbones+   -  Reputation: 2974

Like
0Likes
Like

Posted 20 November 2012 - 12:56 AM

Please post the exact error text.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#10 C0lumbo   Crossbones+   -  Reputation: 2216

Like
1Likes
Like

Posted 20 November 2012 - 02:54 AM

The problem is that string is defined as std::string, and it must be being defined somewhere else too, but there's not enough information posted to work out where. If you get rid of the 'using namespace std;' line and add the necessary std:: bits, then the error will go away.

It's often considered unwise to use the 'using' keyword in a header file. I'd advise you to get rid of that habit, and keep any 'using' stuff to your .cpp files.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS