Skip to main content
gamedev.net
🔒 Locked

game engine problems

Started by exorcist_bob Apr 27, 2006 at 5:42 PM 7 replies 1.1k views
Original Post
exorcist_bob
exorcist_bob
Hello, I have been struggling on what seems to be an easy problem for the last few days. In my module SWMAngle.h I have a two classes defined, SWMDegree and SWMRadian. They are surrounded by the namespace 'SkepWorks'. So I have something like this:

namespace SkepWorks
{
class SWMDegree
{
//stuff
}
class SWMRadian
{
//stuff
}
}

Now I have another module, math, that wants to use it, SWMMath.h. This module is also in the same namespace. But it can't find it! I have included SWMAngle. I put in SkepWorks:: for every instance of SWMDegree/Radian, but it says that it isn't in the namespace. SWMMath.h

#include "SWMAngle.h"
namespace SkepWorks
{
class Math
static inline SkepWorks::SWMDegree Abs (const SWMDegree& dValue) { return SWMDegree(fabs(dValue.GetDegrees())); }
}

Errors: error C2039: 'SWMDegree' : is not a member of 'SkepWorks' error C2146: syntax error : missing ';' before identifier 'Abs' Thanks for any help, exorcist_bob
Palidine
Palidine
Can you post your actual code? What you have there has other errors: missing ';' after your class declerations. Also, what's that line class Math doing there? There is niether a trailing ';' which would make it a forward decleration, nor is there an opening '{' which would make it an actual class definition.

Otherwise, my hunch is that you should not have the leading 'SkepWorks::' in your static function decleration. You are already inside the SkepWorks namespace and should not need to scope the variable.

-me
discman1028
discman1028
And, you'd probably want a '::' between 'SWMDegree' and 'Abs' in SWMMath.h.
--== discman1028 ==--
Deyja
Deyja
namespace SkepWorks{class SWMDegree{//stuff}; <--semicolon hereclass SWMRadian{//stuff}; <--and here}; <--guess.


#include "SWMAngle.h"namespace SkepWorks{class Math { <-- open the class definitionstatic inline SkepWorks::SWMDegree Abs (const SWMDegree& dValue) { return SWMDegree(fabs(dValue.GetDegrees())); }}; <-- close class + semicolon}; <-- semicolon!!


Your second error is actually caused by the first. The compiler bombs while trying to grok your type definition, so it just gives up and starts at the next token, assuming it starts a brand new statement. Of course, you can't start a new statement without a control character before it, so it goes looking for a semicolon and can't find it. It's a rather common error sequence. You'll see type errors followed by 'expected a semicolon' a lot.

As for your original error, if the code you posted is actually from your project, it has some serious syntactical issues. If it's not the real code, then don't expect us to see the problem.
exorcist_bob
exorcist_bob
Eek! Sorry, i just put down improvised code, not code directly from my engine. Sorry, but nothing that you have suggested has worked.

Direct source from engine:

SWMAngle.h:
#pragma once#include "SkepWorks.h"#include "SWMMath.h"#include "SWMDefines.h"namespace SkepWorks{	class SkepWorksExport SWMAngle	{	public:		SWMAngle(void);	public:		~SWMAngle(void);	};	class SkepWorksExport SWMDegree;	class SkepWorksExport SWMRadian	{		SWFloat mRad;	public:		/*		explicit SWMRadian ( SWFloat r=0 ) : mRad(r) {}		SWMRadian ( const SWMDegree& d );		const SWMRadian& operator = ( const SWFloat& f ) { mRad = f; return *this; }		const SWMRadian& operator = ( const SWMRadian& r ) { mRad = r.mRad; return *this; }		const SWMRadian& operator = ( const SWMDegree& d );		*/		SWFloat GetDegrees() const;		SWFloat GetRadians() const { return mRad; }		SWFloat ToAngleUnits() const;		/*		SWMRadian operator + ( const SWMRadian& r ) const { return SWMRadian ( mRad + r.mRad ); }		SWMRadian operator + ( const SWMDegree& d ) const;		SWMRadian& operator += ( const SWMRadian& r ) { mRad += r.mRad; return *this; }		SWMRadian& operator += ( const SWMDegree& d );		SWMRadian operator - () { return SWMRadian(-mRad); }		SWMRadian operator - ( const SWMRadian& r ) const { return SWMRadian ( mRad - r.mRad ); }		SWMRadian operator - ( const SWMDegree& d ) const;		SWMRadian& operator -= ( const SWMRadian& r ) { mRad -= r.mRad; return *this; }		SWMRadian& operator -= ( const SWMDegree& d );		SWMRadian operator * ( SWFloat f ) const { return SWMRadian ( mRad * f ); }		SWMRadian operator * ( const SWMRadian& f ) const { return SWMRadian ( mRad * f.mRad ); }		SWMRadian& operator *= ( SWFloat f ) { mRad *= f; return *this; }		SWMRadian operator / ( SWFloat f ) const { return SWMRadian ( mRad / f ); }		SWMRadian& operator /= ( SWFloat f ) { mRad /= f; return *this; }		bool operator <  ( const SWMRadian& r ) const { return mRad <  r.mRad; }		bool operator <= ( const SWMRadian& r ) const { return mRad <= r.mRad; }		bool operator == ( const SWMRadian& r ) const { return mRad == r.mRad; }		bool operator != ( const SWMRadian& r ) const { return mRad != r.mRad; }		bool operator >= ( const SWMRadian& r ) const { return mRad >= r.mRad; }		bool operator >  ( const SWMRadian& r ) const { return mRad >  r.mRad; }		*/	};	class SkepWorksExport SWMDegree	{		SWFloat mDeg;	public:		/*		explicit SWMDegree ( SWFloat d=0 ) : mDeg(d) {}		SWMDegree ( const SWMRadian& r ) : mDeg(r.GetDegrees()) {}		const SWMDegree& operator = ( const SWFloat& f ) { mDeg = f; return *this; }		const SWMDegree& operator = ( const SWMDegree& d ) { mDeg = d.mDeg; return *this; }		const SWMDegree& operator = ( const SWMRadian& r ) { mDeg = r.GetDegrees(); return *this; }		*/		SWFloat GetDegrees() const { return mDeg; }		SWFloat GetRadians() const;		SWFloat ToAngleUnits() const;		/*		SWMDegree operator + ( const SWMDegree& d ) const { return SWMDegree ( mDeg + d.mDeg ); }		SWMDegree operator + ( const SWMRadian& r ) const { return SWMDegree ( mDeg + r.GetDegrees() ); }		SWMDegree& operator += ( const SWMDegree& d ) { mDeg += d.mDeg; return *this; }		SWMDegree& operator += ( const SWMRadian& r ) { mDeg += r.GetDegrees(); return *this; }		SWMDegree operator - () { return SWMDegree(-mDeg); }		SWMDegree operator - ( const SWMDegree& d ) const { return SWMDegree ( mDeg - d.mDeg ); }		SWMDegree operator - ( const SWMRadian& r ) const { return SWMDegree ( mDeg - r.GetDegrees() ); }		SWMDegree& operator -= ( const SWMDegree& d ) { mDeg -= d.mDeg; return *this; }		SWMDegree& operator -= ( const SWMRadian& r ) { mDeg -= r.GetDegrees(); return *this; }		SWMDegree operator * ( SWFloat f ) const { return SWMDegree ( mDeg * f ); }		SWMDegree operator * ( const SWMDegree& f ) const { return SWMDegree ( mDeg * f.mDeg ); }		SWMDegree& operator *= ( SWFloat f ) { mDeg *= f; return *this; }		SWMDegree operator / ( SWFloat f ) const { return SWMDegree ( mDeg / f ); }		SWMDegree& operator /= ( SWFloat f ) { mDeg /= f; return *this; }		bool operator <  ( const SWMDegree& d ) const { return mDeg <  d.mDeg; }		bool operator <= ( const SWMDegree& d ) const { return mDeg <= d.mDeg; }		bool operator == ( const SWMDegree& d ) const { return mDeg == d.mDeg; }		bool operator != ( const SWMDegree& d ) const { return mDeg != d.mDeg; }		bool operator >= ( const SWMDegree& d ) const { return mDeg >= d.mDeg; }		bool operator >  ( const SWMDegree& d ) const { return mDeg >  d.mDeg; }		*/	};};


SWMMath.h:
#pragma once#include "SkepWorks.h"#include "SWMDefines.h"#include "SWMAngle.h"namespace SkepWorks{	class SkepWorksExport SWMMath	{	public:	/** The angular units used by the API. This functionality is now deprecated in favor	of discreet angular unit types ( see SWMDegree and SWMRadian above ). The only place	this functionality is actually still used is when parsing files. Search for	usage of the Angle class for those instances	*/		enum AngleUnit		{			AU_DEGREE,			AU_RADIAN		};	protected:		// angle units used by the api		static AngleUnit msAngleUnit;		/// Size of the trig tables as determined by constructor.		static int mTrigTableSize;		/// SWMRadian -> index factor value ( mTrigTableSize / 2 * PI )		static SWFloat mTrigTableFactor;		static SWFloat* mSinTable;		static SWFloat* mTanTable;		/** Private function to build trig tables.		*/		void buildTrigTables();		static SWFloat SinTable (SWFloat fValue);		static SWFloat TanTable (SWFloat fValue);	public:		/** Default constructor.		@param		trigTableSize Optional parameter to set the size of the		tables used to implement Sin, Cos, Tan		*/		SWMMath(unsigned int trigTableSize = 4096);		/** Default destructor.		*/		~SWMMath();		static inline int IAbs (int iValue) { return ( iValue >= 0 ? iValue : -iValue ); }		static inline int ICeil (float fValue) { return int(ceil(fValue)); }		static inline int IFloor (float fValue) { return int(floor(fValue)); }		static int ISign (int iValue);		static inline SWFloat Abs (SWFloat fValue) { return SWFloat(fabs(fValue)); }		static inline SkepWorks::SWMDegree Abs (const SWMDegree& dValue) { return SWMDegree(fabs(dValue.GetDegrees())); }		static inline SWMRadian Abs (const SWMRadian& rValue) { return SWMRadian(fabs(rValue.GetRadians())); }		static SWMRadian ACos (SWFloat fValue);		static SWMRadian ASin (SWFloat fValue);		static inline SWMRadian ATan (SWFloat fValue) { return SWMRadian(atan(fValue)); }		static inline SWMRadian ATan2 (SWFloat fY, SWFloat fX) { return SWMRadian(atan2(fY,fX)); }		static inline SWFloat Ceil (SWFloat fValue) { return SWFloat(ceil(fValue)); }		/** Cosine function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Cos (const SWMRadian& fValue, bool useTables = false) 		{			return (!useTables) ? SWFloat(cos(fValue.GetRadians())) : SinTable(fValue.GetRadians() + HALF_PI);		}		/** Cosine function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Cos (SWFloat fValue, bool useTables = false) 		{			return (!useTables) ? SWFloat(cos(fValue)) : SinTable(fValue + HALF_PI);		}		static inline SWFloat Exp (SWFloat fValue) { return SWFloat(exp(fValue)); }		static inline SWFloat Floor (SWFloat fValue) { return SWFloat(floor(fValue)); }		static inline SWFloat Log (SWFloat fValue) { return SWFloat(log(fValue)); }		static inline SWFloat Pow (SWFloat fBase, SWFloat fExponent) { return SWFloat(pow(fBase,fExponent)); }		static SWFloat Sign (SWFloat fValue);		static inline SWMRadian Sign ( const SWMRadian& rValue )		{		return SWMRadian(Sign(rValue.GetRadians()));		}		static inline SWMDegree Sign ( const SWMDegree& dValue )		{		return SWMDegree(Sign(dValue.GetDegrees()));		}		/** Sine function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Sin (const SWMRadian& fValue, bool useTables = false) 		{			return (!useTables) ? sin(fValue.GetRadians()) : SinTable(fValue.GetRadians());		}		/** Sine function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Sin (SWFloat fValue, bool useTables = false) 		{			return (!useTables) ? SWFloat(sin(fValue)) : SinTable(fValue);		}		static inline SWFloat Sqr (SWFloat fValue) { return fValue*fValue; }		static inline SWFloat Sqrt (SWFloat fValue) { return SWFloat(sqrt(fValue)); }		static inline SWMRadian Sqrt (const SWMRadian& fValue) { return SWMRadian(sqrt(fValue.GetRadians())); }		static inline SWMDegree Sqrt (const SWMDegree& fValue) { return SWMDegree(sqrt(fValue.GetDegrees())); }		/** Inverse square root i.e. 1 / Sqrt(x), good for vector		normalisation.		*/		static SWFloat InvSqrt(SWFloat fValue);		static SWFloat UnitRandom ();  // in [0,1]		static SWFloat RangeRandom (SWFloat fLow, SWFloat fHigh);  // in [fLow,fHigh]		static SWFloat SymmetricRandom ();  // in [-1,1]		/** Tangent function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Tan (const SWMRadian& fValue, bool useTables = false) 		{			return (!useTables) ? tan(fValue.GetRadians()) : TanTable(fValue.GetRadians());		}		/** Tangent function.		@param		fValue Angle in radians		@param		useTables If true, uses lookup tables rather than		calculation - faster but less accurate.		*/		static inline SWFloat Tan (SWFloat fValue, bool useTables = false) 		{			return (!useTables) ? SWFloat(tan(fValue)) : TanTable(fValue);		}		static inline SWFloat DegreesToRadians(SWFloat degrees) { return degrees * fDeg2Rad; }		static inline SWFloat RadiansToDegrees(SWFloat radians) { return radians * fRad2Deg; }		/** These functions used to set the assumed angle units (radians or degrees) 		expected when using the Angle type.		@par		You can set this directly after creating a new Root, and also before/after resource creation,		depending on whether you want the change to affect resource files.		*/		static void setAngleUnit(AngleUnit unit);		/** Get the unit being used for angles. */		static AngleUnit getAngleUnit(void);		/** Convert from the current AngleUnit to radians. */		static SWFloat AngleUnitsToRadians(SWFloat units);		/** Convert from radians to the current AngleUnit . */		static SWFloat RadiansToAngleUnits(SWFloat radians);		/** Convert from the current AngleUnit to degrees. */		static SWFloat AngleUnitsToDegrees(SWFloat units);		/** Convert from degrees to the current AngleUnit. */		static SWFloat DegreesToAngleUnits(SWFloat degrees);		static const SWFloat POS_INFINITY;		static const SWFloat NEG_INFINITY;		static const SWFloat PI;		static const SWFloat TWO_PI;		static const SWFloat HALF_PI;		static const SWFloat fDeg2Rad;		static const SWFloat fRad2Deg;	};};


Thanks,
exorcist_bob
Golden Dragon
Golden Dragon
Namespaces should NOT have a semicolon at the end of them, unlike classes.
try removing them and see what happens
Deyja
Deyja
Actually, the semicolon at the end of a namespace is meaningless. I'm just in the habit of sticking them there. Semicolons floating around by themselves are harmless.

Anyway, the problem is that SWMMath.h includes SWMAngle.h, which includes SWMMath.h. So, all that stuff in SWMMath.h that uses SWMAngle.h ends up being seen before the compiler sees anything in SWMAngle.h. Since it doesn't appear that the interface of SWMDegree depends on SWMMath.h, just move SWMDegree's implementation into a cpp file, include SWMMath.h there, and remove the include from SWMAngle.h.
exorcist_bob
exorcist_bob
Wow, thanks a lot! I thought it was something simple.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.