bonjour,

J'essaye de créer un singleton mais j'ai les erreurs suivantes :

cSpectatorController.obj : error LNK2005: "private: static class cApplication * cApplication::_singleton" (?_singleton@cApplication@@0PAV1@A) déjà défini(e) dans cApplication.obj
main.obj : error LNK2005: "private: static class cApplication * cApplication::_singleton" (?_singleton@cApplication@@0PAV1@A) déjà défini(e) dans cApplication.obj
voici le code de mon singleton :

.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _APPLICATION_
#define _APPLICATION_
 
#include <Ogre.h>
#include <OIS/OIS.h>
#include <CEGUI/CEGUI.h>
#include <OgreCEGUIRenderer.h>
 
#include "cInputListener.h"
#include "cPlayerController.h"
 
#include "NxPhysics.h"
 
using namespace Ogre;
 
 
class cApplication
{
private:
	static cApplication *_singleton;
 
	Root *mRoot;
	OIS::Keyboard *mKeyboard;
	OIS::Mouse * mMouse;
	OIS::InputManager *mInputManager;
 
	CEGUI::OgreCEGUIRenderer *mRenderer;
	CEGUI::System *mSystem;
 
	cInputListener* mListener;
	cPlayerController* mPlayerController;
	FrameListener* mPlayerFrameListener;
 
	NxPhysicsSDK* mPhysXSDK;
	NxScene * mPXScene;
 
	void createRoot();
    void defineResources();
    void setupRenderSystem();
    void createRenderWindow();
    void initializeResourceGroups();
    void setupScene();
	void setupInputSystem();
	void createGUI();
    void setupCEGUI();
    void createFrameListener();
    void startRenderLoop();
	void addPlayer();
	void setupPhysics();
	cApplication(void);
	~cApplication(void);
 
public:
	inline Root* getRoot(){ return mRoot; }
	inline OIS::Keyboard * getKeyBoard(){ return  mKeyboard; }
	inline OIS::Mouse * getMouse(){ return mMouse;}
	inline OIS::InputManager * getInputManager(){ return mInputManager; }
 
	inline CEGUI::OgreCEGUIRenderer * getRenderer() { return mRenderer; }
	inline CEGUI::System * getSystem() { return  mSystem; }
 
	inline NxPhysicsSDK* getPhysxSDK() { return  mPhysXSDK; }
	inline NxScene * getPhysxScene() { return  mPXScene; }
 
	static cApplication* getSingletonPtr();
	static void kill ();
	void go();
};
cApplication *cApplication::_singleton = 0;
 
#endif
.cpp (je vous passe toutes les autres fonctions)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cApplication* cApplication::getSingletonPtr(){
	if (_singleton == 0)
		_singleton =  new cApplication;
	return _singleton;
}
 
void cApplication::kill ()
{
	if (_singleton != 0)
	  {
		delete _singleton;
		_singleton = NULL;
	  }
}
et les deux appels :

main.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
#include "cApplication.h"
 
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include "windows.h"
 
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    try {
		cApplication* app = cApplication::getSingletonPtr();
		app->go();
    } catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 
        MessageBox( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occurred: %s\n",
                e.what());
#endif
    }
 
    return 0;
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
	if(mMouse->getMouseState().buttonDown(OIS::MouseButtonID::MB_Left)){
		cApplication::getSingletonPtr();
	}
Il me semble pourtant avoir respecté scrupuleusement les indications des différents tutos que j'ai trouvé, mais rien n'y fait.

merci