Jump to content
  • Advertisement
Sign in to follow this  
BlessmanTsanga

Singletons (class templates and pure virtual functions)

This topic is 2559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi

Im trying to create a singleton but visual studio is rejecting my private constructor.
Why is this? aren't singleton constructors meant to be private or is it that they are shunned by visual studio?

class CStart_Menu :
public CStates<CGAME_MANAGER>
{
private:

CStart_Menu();

public:
//BEGIN STATE:
virtual FAST_BOOL Enter(CGAME_MANAGER* qp_laststate)


[output]1>Start_Menu.obj : error LNK2019: unresolved external symbol "private: __thiscall
CStart_Menu::CStart_Menu(void)" (??0CStart_Menu@@AAE@XZ) referenced in function
"public: static class CStart_Menu * __cdecl CStart_Menu::Instance(void)" (?
Instance@CStart_Menu@@SAPAV1@XZ)

1>Start_Menu.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall
CStates<class CGAME_MANAGER>::~CStates<class CGAME_MANAGER>(void)" (??1?
$CStates@VCGAME_MANAGER@@@@UAE@XZ) referenced in function "public: virtual __thiscall
CStart_Menu::~CStart_Menu(void)" (??1CStart_Menu@@UAE@XZ)

1>c:\users\portsmouthuni\documents\visual studio
2010\Projects\consolegamestate\Debug\consolegamestate.exe : fatal error LNK1120: 2
unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
[/output]

Share this post


Link to post
Share on other sites
Advertisement
It's complaining that it can't find the function bodies for the functions. You might want to implement them.

Share this post


Link to post
Share on other sites

It's complaining that it can't find the function bodies for the functions. You might want to implement them.


I've done that yet its till there. its been 5 hours now and i'm seriously behind

Share this post


Link to post
Share on other sites
this is the instance I want my singletons to be controlled by


#pragma once
#ifndef _GAME_MANAGER_ZUMA_H
#define _GAME_MANAGER_ZUMA_H
#include "StateMachine.h"
//*********************************************************************************************
//Purpose: Managing the game state
//Type:
//
//*********************************************************************************************
class CGAME_MANAGER{
private:
//use our state machine
CStateMachine<CGAME_MANAGER> * qmpStateMachine;

public:
CGAME_MANAGER();


~CGAME_MANAGER(void);

//add class methods here...
void Update(void);

CStateMachine<CGAME_MANAGER>* Use_StateMachine();

};

#endif



Basically here is where I create my state;

#pragma once
#ifndef _MY_STATES_MENU_H
#define _MY_STATES_MENU_H
#include "states.h"
#include "GAME_MANAGER.h"
/****************************************************
//Purpose: This is the menu at the start of the game
*****************************************************/
class CStart_Menu :
public CStates<CGAME_MANAGER>
{
private:
//CStart_Menu(void);

public:
//BEGIN STATE:
//take message from previus state
//to see if transisation is possible
// return 1 for success, 0 for fail
virtual FAST_BOOL Enter(CGAME_MANAGER* qp_laststate);


//EXECUTE OUR STATE:
//Now lets get things rolling
virtual void Execute(CGAME_MANAGER* q);

//EXITING STATE:
//Pass message to our successor
//return our address to let the successor know,
//this message affects the call of action of our successor
virtual CStates<CGAME_MANAGER>* Exit(CGAME_MANAGER* q);
//SINGLETON DECLARATION
CStart_Menu* Instance();


//virtual ~CStart_Menu(void);
};

#define stSTART_MENU CStart_Menu::Instance()

#endif


And finally here is where it rejects my singleton :(sad.gifsad.gif:(

#include "GAME_MANAGER.h"
#include "Start_Menu.h"

CGAME_MANAGER qGameManager;

int main()
{
qGameManager.Use_StateMachine()/*->ChangingState(stSTART_MENU)*/;

qGameManager.~CGAME_MANAGER();
return 0;
}

Share this post


Link to post
Share on other sites
There's a distinct lack of function definitions in the code you just posted. The function definitions are the parts with the curly braces that have statements inside that determine what the functions actually do. Your main() function has a definition, but nothing else seems to.

Share this post


Link to post
Share on other sites
Do you know the difference between a declaration and a definition? If not, now would be the time to learn it via Google.

As a side note, any time you need to use singletons, you have done something wrong. There is always a better choice.
Even Morgan Stanley and Square Enix agree.


L. Spiro


[EDIT]
Would the person who provided me with this lovely red -1 explain whether it was due to my suggestion regarding Google or because of a personal opinion that there is some justification to use a singleton?

If you disagree with something, you should explain why.
[/EDIT]

Share this post


Link to post
Share on other sites
Prove it. Show us the .CPP files.

Because right now there are only 2 possibilities.
#1: Either you didn’t write the functions.
#2: Or you are using static libraries and are not linking to them from the main project.


L. Spiro

Share this post


Link to post
Share on other sites
Do you have function bodies for CStart_Menu::CStart_Menu() and CStates::~CStates() ?

Note that you should not be explicitly calling a destructor, unless you are 200% sure of what you are doing. The compiler will emit a call to the destructor after main(), so you've actually asked to run the destructor twice there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!