Parse error issue

Started by
19 comments, last by Enigma 18 years, 8 months ago
I am getting a parse error, but I can't figure out why. I have a static class defined as such: ConcreteFactory.h

/*
 *  ConcreteFactory.h
 *  Symphony Engine
 *
 *  Created by Corey Hoffstein on 8/31/05.
 *  Copyright 2005 Corey Hoffstein. All rights reserved.
 *
 */

#ifndef __CONCRETEFACTORY_H__
#define __CONCRETEFACTORY_H__

//#include "precompiled.h"

#include "Logger.h"
#include "AudioCore.h"
#include "InputManager.h"
#include "ResourceCore.h"
#include "ObjectFactory.h"

namespace Symphony
{
	class ConcreteFactory
	{
		private:
			static Logger *l;
			static AudioCore *ac;
			static InputManager *im;
			static ResourceCore *rc;
			static ObjectFactory *of;

		public:
			ConcreteFactory()
			{
			}
			~ConcreteFactory()
			{
			}
			
			static inline void createFactory()
			{
				l = new Logger();
				ac = new AudioCore();
				im = new InputManager();
				rc = new ResourceCore();
				of = new ObjectFactory();
			}
			
			static inline void destroyFactory()
			{
				//delete our audio core, input manager, and resource core
				if(ac) delete ac;
				if(im) delete im;
				if(rc) delete rc;
				
				//delete the object factory
				if(of) delete of;
				
				//close our logger
				if(l) delete l;
			}
			
			static inline Logger *getLogger()
			{
				return l;
			}
			static inline AudioCore *getAudioCore()
			{
				return ac;
			}
			static inline InputManager *getInputManager()
			{
				return im;
			}
			static inline ResourceCore *getResourceCore()
			{
				return rc;
			}
			static inline ObjectFactory *getObjectFactory()
			{
				return of;
			}
	};	
}
#endif

ConcreteFactory.cpp

/*
 *  ConcreteFactory.cpp
 *  Symphony Engine
 *
 *  Created by Corey Hoffstein on 8/31/05.
 *  Copyright 2005 Corey Hoffstein. All rights reserved.
 *
 */

#include "ConcreteFactory.h"

using namespace Symphony;

Logger *ConcreteFactory::l = NULL;
AudioCore *ConcreteFactory::ac = NULL;
InputManager *ConreteFactory::im = NULL;
ResourceCore *ConreteFactory::rc = NULL;
ObjectFactory *ConreteFactory::of = NULL;

Everything seems fine to me -- maybe not? Anyway, so I try to use it like this:

#include "ConcreteFactory.h"

...
ptr = ConcreteFactory::getObjectFactory()->createInstance(name, ptr);

And this is the error: error: parse error before `;' token Thoughts about this? Thanks.
Advertisement
You didn't say on which line (and in which file) the parse error occurred.
If it was on one of the lines:

Logger *ConcreteFactory::l = NULL;
AudioCore *ConcreteFactory::ac = NULL;
InputManager *ConreteFactory::im = NULL;
ResourceCore *ConreteFactory::rc = NULL;
ObjectFactory *ConreteFactory::of = NULL;

it may be because NULL is not defined. Replace all NULLs with 0 (zero). Alternatively you can include the header where NULL is defined (don't know which one), but using zero instead is recommended for C++ code (0 is a valid value for a pointer of any type).

If this didn't help you, please post the filename and line number where the error occurred.
Whoops, sorry about that. On this line:

ptr = ConcreteFactory::getObjectFactory()->createInstance(name, ptr);

It was used before in a singleton instance, like this: ObjectFactory::getInstance()->, so I know that the issue is with the new ConcreteFactory.

Thanks.
I assume the error occured on the line posted in the third sourcecode box. Did you bring the name ConcreteFactory into scope using a using declaration?

Enigma
using namespace Symphony;Logger *ConcreteFactory::l = NULL;AudioCore *ConcreteFactory::ac = NULL;InputManager *ConreteFactory::im = NULL;ResourceCore *ConreteFactory::rc = NULL;ObjectFactory *ConreteFactory::of = NULL;

Don't do this. Using directives merely import the requested symbols into the current scope. They don't actually place things in there. Try this instead:
namespace Symphony{Logger *ConcreteFactory::l = NULL;AudioCore *ConcreteFactory::ac = NULL;InputManager *ConreteFactory::im = NULL;ResourceCore *ConreteFactory::rc = NULL;ObjectFactory *ConreteFactory::of = NULL;}
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
The code it is within is within the Symphony namespace as well. What I mean by that is that code is from within a class, which is also within the Symphony namespace -- as such:
#include "ConcreteFactory.h"namespace Symphony{    class SomeClass    {        private:             ....        public:             inline void someFunction()             {                  ...                  ptr = ConcreteFactory::getObjectFactory()->createInstance(name, ptr);             }    };}



Thanks for the thoughts so far.


EDIT: antareus -- unfortunately, no effect.
I don't see any logic errors in what you've posted so far (barring the issue antareus pointed out - good spot). Can you try breaking the function down into:
ObjectFactory *of = ConcreteFactory::getObjectFactory();
ptr = of->createInstance(name, ptr);
to narrow down where the error is.

The only other thing I can think to suggest without seeing more code is to examine the preprocessor output to check that your inclusion guards haven't been accidentally duplicated in another file or tromped on by a compiler-defined symbol (since it's technically a name reserved for the implementation).

Enigma
Error is in:
ObjectFactory *of = ConcreteFactory::getObjectFactory();
.
Ill see what I can do about preprocessor output (I'm new to xcode...)

Thanks.
I hate bumping, but I am really stuck here.....*bump*
How big is the source? Can you post a zip or cut it down to a small enough test case?

Enigma

This topic is closed to new replies.

Advertisement