Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


cSingleton object problem

This topic is 5292 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

I implemented some of "Richard Fine''s" tutorial code from his series here on Gamedev.net (a great series of tutorials if you''re looking to start you''re own engine of sorts). Anyway, the code worked flawlessly on MSVC++ 6.0 SP5; but when I decided to port it over to linux to design a server, it started to hit the fan. Most of the mistakes were the "allowances" that the MSVC++ compiler gives to the programmer that G++ doesn''t (it''s following strict ISO C++ standards). Those weren''t the big problem, I was able to fix those small little bugs. But I''m a little confused at his point, the singleton object, isn''t compiling at all, and I can''t figure out why! Even the error message I''ve never seen before (and I''ve had a lot of errors on GNU compilers before ;o). Here''s the error''s it''s producing:
core/Main.cpp:44: ISO C++ forbids declaration of `Destroy'' with no type
core/Main.cpp:44: no `int Base::cEngine::Destroy()'' member function declared in 
   class `Base::cEngine''
core/Main.cpp:44: declaration of `int Base::cEngine::Destroy()'' outside of 
   class is not definition
core/Main.cpp:45: ISO C++ forbids declaration of `Destroy'' with no type
core/Main.cpp:45: cannot declare member function `Memory::cMemoryManager::
   Destroy'' within `Base::cEngine''
core/Main.cpp:46: ISO C++ forbids declaration of `GetSingleton'' with no type
core/Main.cpp:46: cannot declare member function `Base::cLog::GetSingleton'' 
   within `Base::cEngine''
core/Main.cpp:46: syntax error before `.'' token
core/Main.cpp:48: ISO C++ forbids declaration of `GetSingleton'' with no type
core/Main.cpp:48: cannot declare member function `Base::cLog::GetSingleton'' 
   within `Base::cEngine''
core/Main.cpp:48: syntax error before `.'' token
core/Main.cpp:49: ISO C++ forbids declaration of `Destroy'' with no type
core/Main.cpp:49: cannot declare member function `Base::cLog::Destroy'' within `
int main(int argc,char *argv[]) { ///////////////////////////////////

    // why not start with setting up the logger?

	cLog::Create( );
	cLog::GetSingleton( ).Initalize( );

	// we need to start the memory manager

	LOG("Init: Starting Memory Manager");
	Memory::cMemoryManager::Create( );

	LOG("Init: Starting Platform");   
    // let''s start up the platform that this bitch runs on!

	if(!(Platform::Initalize(void))) {
		// something went wrong didn''t she doc?

		BUG("Platform::Initalize","could not initalize platform");		
		cLog::GetSingleton( ).Shutdown( );
		cLog::Destroy( );
		Memory::cMemoryManager::Destroy( );
		return -1;

    //j: now we create the engine

	Base::cEngine::Create( );

	ENGINE.Run( );

	LOG("Down: Starting Shutdown");
	ENGINE.Shutdown( );

	Platform::Release( );

	Base::cEngine::Destroy( );
	Memory::cMemoryManager::Destroy( );
	LOG("Down: Shutdown Complete");

	cLog::GetSingleton( ).Shutdown();
	cLog::Destroy( );
	return 1;
template<typename T>
 class cSingleton {
	 static T* ms_singleton;
		 cSingleton() {
			int offset=(int)(T*)1-(int)(cSingleton <T>*)(T*)1;
		 ~cSingleton() {
		static inline void Create() {
			new T();
		static inline void Destroy() {
				delete ms_singleton;
		static inline T& GetSingleton() {
			return *ms_singleton;
		static inline T* GetSingletonPtr() {
			return ms_singleton;
 template <typename T> T* cSingleton <T>::ms_singleton=0;
Mind you, everything above has worked fine on Windows, so I know the code isn''t "flawed" (although you might want to call it that since it''s not following ISO standards) but I''m still trying to figure out why Destroy and GetSingleton are messing up! Any suggestions would be greatly appreciiated! Thanks everyone in advance, this community is the best -John "bkt" Bellone Flipside Software FlipEngine!

Share this post

Link to post
Share on other sites
Oh yeah, forgot to post the code for Base.h and the cEngine class instance. This is where the errors are being produced (as well with cLog.h, but I guess if one is both have something wrong it''ll end up being in cSingleton).


class cEngine : public cSingleton<cEngine> {
virtual ~cEngine(void);

void Run(void);
void Shutdown(void);

// put all the layers here

iMPointer<Network::cNetworkLayer> networkLayer;
unsigned int m_iServerPort;

Share this post

Link to post
Share on other sites
The only thing that I can think of that would keep that from compiling under linux would be case mis-matching when you #include the headers, although I can't tell from here as you didn't post the full files.

[edited by - bytecoder on May 22, 2004 2:07:43 PM]

Share this post

Link to post
Share on other sites

  • 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!