I have 3 header files in my project and 3 .cpp files:
main.cpp, game.cpp, player.cpp
defines.h, game.h, and player.h
======================================================
In defines.h there are defined constants example:
1 2 3 4 5 6
|
#include <iostream>
#include <windows.h>
//inside define.h
#define CIREASA 'C'
#define STEA 'S'
|
In player.h there is the Player class declaration..
In player.cpp there is the Player class implementation.
In game.h there is the Game class declaration
In game.cpp the Game class functions are implemented.
The game.cpp requires player.cpp and there is some error at linking
and i don't know why.. something about multiple definitions..?
Here is the error code generated:
==================================
Linking console executable: bin\Debug\SizzlingHot.exe
obj\Debug\player.o: In function `_ZN6PlayerD1Ev':
player.cpp:(.bss+0x0): multiple definition of `_player'
/main.cpp:(.bss+0x18): first defined here
obj\Debug\player.o: In function `_ZN6PlayerD1Ev':
/player.cpp:(.bss+0xc): multiple definition of `_game'
/main.cpp:(.bss+0x0): first defined here
game.o: In function `_ZSt3minIjERKT_S2_S2_':
/game.cpp:(.bss+0x0): multiple definition of `_game'
and a few more..just like this..
Here some more info that might help:
===========================
1 2 3 4 5
|
//inside main.cpp
#include "defines.h"
#include "game.h"
#include "player.h"
|
1 2 3 4 5 6 7 8 9 10 11
|
//inside game.h
#ifndef _game_h
#define _game_h
class Game {
public:
void print(int); //print the board and fruits
bool randomChance (unsigned int chance); //randomChance
void initBoard(); //initialzes the board with fruits
//...code continues....
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12
|
//inside defines.h
#ifndef _defines_h
#define _defines_h
#include <iostream>
#include <windows.h>
#define CIREASA 'C'
#define STEA 'S'
#define SAPTE '7'
#define LAMAIE 'l'
//...code continues .. only #define CONSTANT stuff
|
1 2 3 4 5 6 7 8 9 10 11
|
//inside player.h
#ifndef _player_h
#define _player_h
class Player {
public:
bool isOutOfMoney(); //check if player is out of money
void increaseBet(int); //increases player's bet
void decreaseBet(int); //decreases player's bet
//...code continues...
#endif
|
Also probably really important.. and probably the problem:
============================================
1 2 3 4 5
|
//inside game.cpp
#include "game.h"
#include "player.h"
#include "defines.h"
/* FUNCTION IMPLEMENTATION */
|
1 2 3 4 5
|
//inside player.cpp
#include "player.h"
#include "game.h"
#include "defines.h"
/* FUNCTION IMPLEMENTATION */
|
I'm not sure how to make it work... the .cpp files need all those headers
So what is the problem ? I can't really tell.. it's the first project
in which I separated the code into multiple files