Redeclared class?

Hi,

I have this code as shown:

1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
* The Amazing Journey
* main.cpp 
*/ 
#include <cstdlib>
#include "Setup.h"
#include "SETUPDEFINE.h";
using namespace std
int main(){
	Player P1;
	GameSetup::Setup(P1);
return 0 ;
}

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 *  Setup.cpp
 *  TheAmazingJourney
 *
 *  Created by Nicky on 5/14/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#include "Setup.h"
#include <iostream>
#include "SETUPDEFINE.h"
using namespace std;
class GameSetup{
static void Setup(Player& PLAYER){
		string GAMECHOICE = "NULL";
		cout << "***********************\n";
		cout << "****Dungeon Slasher****\n";
		cout << "***********************\n";
		sleep(1);
		string INPUT_RACE;
		srand(time(NULL));
		cout <<"New Game <N>\n";
		cout << "Load Game <L>\n";
	GetMode:
		getline(cin, GAMECHOICE);
		transform(GAMECHOICE.begin(), GAMECHOICE.end(), GAMECHOICE.begin(), ::toupper);
		if(GAMECHOICE == "N"){
			cout << "New game!\n";
			sleep(1);
			
		}
		else{
			cout << "Oops! Only input N, Load function is not working!!";
			goto GetMode;//getline until valid mode is chosen
		};
		cout << "Welcome to DUNGEON SLASHER!\nThis game is a game where you have to slash through monsters to get treasure and defeat the dragon!\n";
		sleep(2);
		cout << "Type Your Race! You can be an ELF, a DWARF, a HALFLING, a HUMAN, or a HALF-ELF";
	GetRace:
		getline(cin, INPUT_RACE);
		transform(INPUT_RACE.begin(), INPUT_RACE.end(), INPUT_RACE.begin(), ::toupper);
		Player::SET_DEFAULTS(PLAYER);
		if (INPUT_RACE == "ELF")Player::SET_ELF(PLAYER);
		else if (INPUT_RACE == "DWARF")Player::SET_DWARF(PLAYER);
		else if (INPUT_RACE == "HALFLING")Player::SET_HALFLING(PLAYER);
		else if (INPUT_RACE == "HUMAN")Player::SET_HUMAN(PLAYER);
		else if (INPUT_RACE == "HALF-ELF")Player::SET_HALF_ELF(PLAYER);
		else{
			cout << "Oops! Your race does not exist. Try typing it again, and be carful of spelling!";
			goto GetRace;//getline again until valid race is chosen
		};
	};
};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 *  Setup.h
 *  TheAmazingJourney
 *
 *  Created by Nicky on 5/14/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef __SETUP_H_INCLUDED__
#define __SETUP_H_INCLUDED__
#include "SETUPDEFINE.h"
#include "Setup.cpp"
static void GameSetup::Setup(Player& PLAYER)
#endif

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *  SETUPDEFINE.h
 *  TheAmazingJourney
 *
 *  Created by Nicky on 5/3/13.
 *  Copyright 2013 SaltPepper. All rights reserved.
 *
 */
//=================================
// include guard
#ifndef __RPGDEFINE_H_INCLUDED__
#define __RPGDEFINE_H_INCLUDED__
//=================================
// forward declared dependencies
//=================================
// included dependencies
//=================================
// the actual class
#define MAX_STATUS 10 
#include <cstdlib>
enum race_t{ELF, DWARF, HALFLING, HUMAN, HALF_ELF};
enum condition_t {HEALTHY, POISONED, WITHER, CLUMSY};
enum magetype_t {FIRE, WATER, EARTH, AIR, DEATH, LIGHT};
enum potion_t{STRONG, FAST, POISON, INSTANTKILL, MAGICAL};
enum weapon_t {SHORT_SWORD, LONG_SWORD, DAGGER, BOW, CROSSBOW, STAFF, WAND};
enum enchantments_t{POISONS, BURN, LIGHTNING, WITHERING, ONEHITKILL, AIRCHANT, NONE};
enum status_t {MELEE, RANGED, WIZARD};
enum weight_t {FEATHER, MEDIUM, HEAVY};
class Player{
public:	
	int MAG;
	int STR;
	int DEX;
	race_t RACE;
	potion_t POTIONEFFECTS;
	condition_t STATUS;
	magetype_t MAGESTATUS;
	weapon_t WEAPON;
	int LEVEL;
	int WEAPONLEVEL;
	enchantments_t ENCHANTMENTS;
	status_t TYPE;
	int WEAPON_INT;
	int ENCHANT_INT;

static void Player::SET_DEFAULTS(Player who){
	who.STR = rand()%7+1;
	who.DEX = rand()%7+1;
	who.MAG = rand()%7+1;
	who.LEVEL = rand()%7+1;
	who.WEAPONLEVEL = rand()%5+1;
	who.STATUS = HEALTHY;
	if(who.STR<4) who.STR++;
	if(who.MAG<4) who.MAG++;
	if(who.DEX<4) who.DEX++;
	if(who.LEVEL<4) who.LEVEL++;
	if(who.WEAPONLEVEL<4) who.WEAPONLEVEL++;
};
static void Player::SET_ELF(Player& who){
	if(who.STR < MAX_STATUS&&who.STR >= 2)who.STR--;
	if(who.DEX + 2 < MAX_STATUS)who.DEX+=2;
	if(who.MAG + 1 < MAX_STATUS)who.MAG++;
	if(who.LEVEL < MAX_STATUS)who.LEVEL--;
	if(who.WEAPONLEVEL < MAX_STATUS)who.WEAPONLEVEL--;
	who.WEAPON_INT = rand()%4+1;
	if (who.WEAPON_INT == 1) who.WEAPON = LONG_SWORD;
	else if (who.WEAPON_INT == 2 || 3) who.WEAPON = BOW;
	else if (who.WEAPON_INT == 4) who.WEAPON = STAFF;
};
static void Player::SET_DWARF(Player &who){
	if(who.STR < MAX_STATUS)who.STR++;
	if(who.DEX < MAX_STATUS)who.DEX--;
	if(who.MAG < MAX_STATUS)who.MAG-=2;
	if(who.WEAPONLEVEL < MAX_STATUS)who.WEAPONLEVEL+= 2;
};
static void Player::SET_HALFLING(Player &who){
	if(who.STR < MAX_STATUS)who.STR--;
	if(who.DEX < MAX_STATUS)who.DEX+=2;
	if(who.MAG < MAX_STATUS)who.MAG++;
	if(who.LEVEL < MAX_STATUS)who.LEVEL--;
	if(who.WEAPONLEVEL < MAX_STATUS)who.WEAPONLEVEL--;
	
};
static void Player::SET_HUMAN(Player& who){
	
};
static void Player::SET_HALF_ELF(Player& who){
	if(who.STR < MAX_STATUS)who.STR--;
	if(who.DEX < MAX_STATUS)who.DEX++;
};
};
#endif  

I get three errors when the code compiles:

Line Location main.cpp:8: error: expected initializer before 'using'
Line Location Setup.cpp:13: error: expected initializer before 'using'
Line Location Setup.cpp:14: previous definition of 'class GameSetup'
Line Location Setup.cpp:14: error: redefinition of 'class GameSetup'

Can someone please help me? I think my classes have gone horribly awry...
I think you need to take a look at how to properly prototype a class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H

class Myclass{ // You prototype here
private:
    int apples;
    int oranges;
    int totalfruit;
public:
    Myclass();
    void set_apples();
    void set_oranges();
    int return_total_fruit();
};

#endif // MYCLASS_H


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Myclass.cpp
#include<iostream> // You define here

void Myclass::set_apples(int a){ // The '::' is the binary scope operator
    Myclass::apples = a;               // You put class name, then function name
}                                                 // then define the function

void Myclass::set_oranges(int o){
    Myclass::oranges = o;
}

int Myclass::return_total_fruit(){
    Myclass::totalfruit = apples + oranges;
    return Myclass::totalfruit; 
}

Topic archived. No new replies allowed.