Bonjour à tous, je fait appel à votre expérience afin de m'aider à corriger un problème dans un programme c++ .
le problème c'est que je reçois le message ci dessous et ne comprend pourquoi :
[linker error] undefined reference 'Game::singleton'
[linker error] undefined reference 'Game::singleton'
[linker error] undefined reference 'Game::singleton'
voici le code si vous voulez y jeter un coup d'oeil:
//fichier Game.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifndef H_Game #define H_Game using namespace std; #include <vector> #include <iostream> #include <stdexcept> #include "Slot.h" #include "types.h" //singleton class class Game{ vector<column> grid; bool humain; Pawn humainPawn; //pointer to singleton static Game* singleton; Game(){} Game(const Game &); ~Game(){delete singleton;} void operator=(const Game &); public: //setters and getters inline bool isHumain(){return humain;} inline Pawn getHumainPawn(){return humainPawn;} inline void setHumain(bool h){humain = h;} inline void setHumainPawn(Pawn hp){humainPawn = hp;} static Game* getInstance(){ if(singleton == NULL){' singleton = new Game; } return singleton; } ostream& operator<< (vector<column> grid); //fin de page 1 //overrides output stream writer void init(bool,Pawn&); //initialises the humain pawn and sets humain turn bool isFreeColumn(int); //return true if column in parameter has a free place for a pawn int getFirstFreeSpot(int); //return the first free place int column given in parameter int whoWins(); //return 1 if humain wins, -1 if computer wins, 0 it is draw game void nextMove()throw (out_of_range&, logic_error&); }; #endif
//fichier Game.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include "Game.h" ostream& operator<<(ostream& out, vector<column> grid){ for(vector<column>::iterator it = grid.begin();it!= grid.end();it++){ column c = *it; for(vector<Slot>::iterator s = c.begin();s!=c.end();s++){ cout << s->getColor() <<endl; } } } void init(bool h,Pawn& hp){ Game* game = Game::getInstance(); game->setHumain(h); game->setHumainPawn(hp); } bool isFreeColumn(int){ } int getFirstFreeSpot(int){ } int whoWins(){ } void nextMove()throw (out_of_range&, logic_error&){ }
Partager