Hi, I've been programming for about half a year. I've not been programming that much though, I've been taking breaks for some weeks or something and then started again, break, start again, break, start again and so on.
Anyways, so in order to remember everything I've learnt from before since my last break was for about 2 months, I've been trying to make a textbased game since it brings up almost everything that I know in programming. But now I have a really frustrating problem that I've been trying to figure out for two days now.
Compiler error: \my textbased game\human warrior (definition).cpp(5): error C2011: 'HumanWarrior' : 'class' type redefinition
Some of the code:
my textbased game.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Human Warrior (declaration).h"
using namespace std;
int main()
{
raceSelectFunction();
classSelectFunction();
cout << "Now that you've chosen race and class you have to choose a name for your character. What do you want the name of your character to be?\n\n";
cin >> characterName;
system ("CLS");
cout << "Your name is " << characterName << ".\n\n";
cout << "Where are you from? Type in the name of the city that you live in\n\n";
cin >> characterCity;
system ("CLS");
cout << "You are from " << characterCity << ".";
Continue();
characterNameClassRaceCity();
cout << "\n\nLet's continue to the actual game";
Continue();
string quit;
cin >> quit;
return 0;
}
|
Human Warrior (declaration).h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class HumanWarrior
{
public:
HumanWarrior(int startHealth, int startStrength, int startAgility, int startStamina);
void stats();
void levelUp();
void afterLvlUp();
private:
int health;
int strength;
int agility;
int stamina;
};
|
Human Warrior (definition).cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include "stdafx.h"
#include "Human Warrior (declaration).h"
class HumanWarrior
{ //(Here's the problem!)
HumanWarrior::HumanWarrior(int startHealth, int startStrength, int startAgility, int startStamina):
health (startHealth), strength (startStrength), agility (startAgility), stamina (startStamina)
{
}
void HumanWarrior::stats()
{
cout << "\n\nYour stats are:\n\n" << "Health: " << health << "\n" << "Strength: " << strength << "\n" << "Agility: " << agility << "\n" << "Stamina: " << stamina << "\n\n";
}
void HumanWarrior::levelUp()
{
health ++;
strength ++;
agility ++;
stamina ++;
cout << "Level Up!\n\n";
}
void HumanWarrior::afterLvlUp()
{
cout << "Your stats are now, after level up, \n\nHealth: " << health << "\n" << "Strength: " << strength << "\n" << "Agility: " << agility << "\n" << "Stamina: " << stamina;
}
};
|
I think I've given enough information. If not, please tell me.
Thanks.
Note: If there are any errors like if a function's name or something is wrong, that's only because I've translated some of the code from swedish, so don't worry about that. Only worry about the error above.