Template Singleton problem
Bonjours,
J'ai crée un template Singleton et une classe qui en hérite.
J'ai un problème lors de l'édition de lien : "unresolved external symbol",
qui provient de la classe dans laquelle j'accède à l'instance du singleton.
La classe template :
Code:
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
|
#ifndef _DEV_SINGLETON_H_
#define _DEV_SINGLETON_H_
#include "DebugNew.h"
template <typename T> class DevSingleton
{
public:
// Get Instance
static T * Instance()
{
if (_singleton == NULL)
{
_singleton = new T;
}
return (_singleton);
}
// Destroy Instance
static void Destroy()
{
if (NULL != _singleton)
{
delete _singleton;
_singleton = NULL;
}
}
protected:
/* Constructor */
DevSingleton() {}
/* Destructor */
~DevSingleton() {}
private:
// Unique instance
static T * _singleton;
};
template <typename T> T * DevSingleton<T>::_singleton = NULL;
#endif _DEV_SINGLETON_H_ |
La classe fille :
Code:
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
|
#ifndef _DEV_INTERNAL_OBJ_
#define _DEV_INTERNAL_OBJ_
#include <d3dx9.h>
#include "d3dfont.h"
#include "DevSingleton.h"
class DevInternalObj : public DevSingleton<DevInternalObj>
{
friend class DevSingleton<DevInternalObj>;
public:
// INTERNAL OBJECTS
IDirect3D9 * pd3d9;
IDirect3DDevice9 * pDevice;
CD3DFont * Font;
private:
// INERNAL MATRICES
private:
DevInternalObj();
~DevInternalObj();
public:
// GET and SET Internal Objects
// GET Matrices
// SET Matrices
};
#endif |
Le constructeur de la classe dans laquelle j'utilise le singleton :
Code:
1 2 3 4 5 6
|
DevRenderer::DevRenderer()
{
DevInternalObj::Instance()->Font = new CD3DFont("Comic sans MS", 12, 0);
} |
Merci d'avance.