Bonjour à tous !!

Je suis en train d'implementer un singleton de la façon suivante :
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
 
#ifndef GLOBAL_STAT_YEAR_FILE_H
#define GLOBAL_STAT_YEAR_FILE_H
 
#include <iostream>
 
class Player;
 
// GlobalStat implementation as a singleton
 
Header :
 
class GlobalStat
{
 
public:
	~GlobalStat();
 
// instanciates a GlobalStat
	static void init(); 
 
// retrieve the static created object  
	static GlobalStat * getInstance();
 
// write the stat on the filestatic GlobalStat * _instance;
	void makeStat(Player * iPlayer, int iYear, const std::string & iNameFile="stat_year.txt");
 
private:
	GlobalStat();
        GlobalStat(const GlobalStat&);
      	GlobalStat& operator= (const GlobalStat&);
 
	static GlobalStat * _instance;
 
};
 
#endif // GLOBAL_STAT_YEAR_FILE_H
Et pour l'mplementation :

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
 
#include "GlobalStat.h"
#include "Player.h"
 
// pointer variable containing a GlobalStat intance
GlobalStat * _instance = NULL;
 
GlobalStat::GlobalStat()
{
}
 
GlobalStat::~GlobalStat()
{
}
 
void GlobalStat::init()
{
	if (_instance == NULL)
		_instance = new GlobalStat;		
}
 
GlobalStat * GlobalStat::getInstance()
{
	return _instance;
}
 
void GlobalStat::makeStat(Player * iPlayer, int iYear, const std::string & iNameFile)
{
	std::cout << "This is the creation of a file" << std::endl;
}
Et je trouve les erreurs :

GlobalStat.o: In function `GlobalStat::getInstance()':
GlobalStat.cpp.text+0x1c): undefined reference to `GlobalStat::_instance'
GlobalStat.o: In function `GlobalStat::init()':
GlobalStat.cpp.text+0xc8): undefined reference to `GlobalStat::_instance'
GlobalStat.cpp.text+0xe8): undefined reference to `GlobalStat::_instance'
collect2: ld returned 1 exit status

Pourquoi ? Comment je peux l'éviter ?

Merci !