#1 Members - Reputation: 343
Posted 19 November 2012 - 08:59 PM
[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"
#2 Members - Reputation: 819
Posted 19 November 2012 - 09:08 PM
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 Members - Reputation: 343
Posted 19 November 2012 - 09:33 PM
"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"
#5 Moderator* - Reputation: 5361
Posted 19 November 2012 - 09:44 PM
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.That doesn't work? Then how about removing
#include <string>
Because usually iostream also includes string.
@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.
#6 Moderators - Reputation: 6623
Posted 19 November 2012 - 09:50 PM
#8 Crossbones+ - Reputation: 3517
Posted 19 November 2012 - 10:16 PM
I would expect the OP to have bigger problems if his standard headers don't have include guards though
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.
#10 Members - Reputation: 913
Posted 20 November 2012 - 02:54 AM
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.






