CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Location
    Vercelli, Italy
    Posts
    87

    Unexpected tokens in a header

    Hi everyone! I'm coding a solar system simulator, and it worked quite good till this morning. I must have done something wrong, but I really can't get what. Maybe a fresh look (or an expert eye ) can see my fault.

    I get the error (for every file that includes "solsys.h")
    Code:
    d:\cpp\solsys\src\solsys.h(29) : error C2629: unexpected 'class SolarSystem::Orbit ('
    d:\cpp\solsys\src\solsys.h(29) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
    The content of solsys.h is here:
    Code:
    #ifndef __SOLAR_SYSTEM_H__
    #define __SOLAR_SYSTEM_H__ 1
    
    #include "vectors.h"
    using math::Vector;
    
    #include <ostream>
    using std::ostream;
    using std::endl;
    
    #ifndef M_PI
    #define M_PI 3.14159265
    #endif
    
    namespace SolarSystem
    {
    
    double EARTH_MASS(5.9736e24);
    double EARTH_RADIUS(6372.797e3);
    double UA(149597870691.0);
    double LIGHT_SPEED(299792458.0);
    double LIGHT_YEAR(9.461e15);
    double SIDEREAL_YEAR(31558149.540);
    
    class Orbit
    {
    public:
    
    	Orbit(	double inclination = 0.0, // in degrees
    			double longitudeOfAscendingNode = 0.0, // in degrees
    			double argumentOfPeriapsis = 0.0, // in degrees
    			double eccentricity = 0.0, 
    			double semimajorAxis = 1, // in UA
    			double meanAnomaly = 0.0 // in degrees
    			double period = 1.0 // in sidereal years
    			) : 
    		_inclination(inclination),
    		_longitudeOfAscendingNode(longitudeOfAscendingNode),
    		_argumentOfPeriapsis(argumentOfPeriapsis),
    		_eccentricity(eccentricity), 
    		_semimajorAxis(semimajorAxis),
    		_meanAnomaly(meanAnomaly),
    		_period(period)
    	{
    	}
    
    	Orbit &setInclination(double val)
    	{
    		_inclination = val;
    		return *this;
    	}
    	Orbit &setLongitudeOfAscendingNode(double val)
    	{
    		_longitudeOfAscendingNode = val;
    		return *this;
    	}
    	Orbit &setArgumentOfPeriapsis(double val)
    	{
    		_argumentOfPeriapsis = val;
    		return *this;
    	}
    	Orbit &setEccentricity(double val)
    	{
    		_eccentricity = val;
    		return *this;
    	}
    	Orbit &setSemimajorAxis(double val)
    	{
    		_semimajorAxis = val;
    		return *this;
    	}
    	Orbit &setMeanAnomaly(double val)
    	{
    		_meanAnomaly = val;
    		return *this;
    	}
    	Orbit &setPeriod(double val)
    	{
    		_period = val;
    		return *this;
    	}
    
    	Vector getPositionAtEpoch(double epoch = 0.0);
    	Vector getPositionAtAngle(double angle = 0.0 /* in degrees */);
    
    	friend ostream &operator<<(ostream &os, Orbit &o);
    
    protected:
    
    	double _inclination;
    	double _longitudeOfAscendingNode;
    	double _argumentOfPeriapsis;
    	double _eccentricity;
    	double _semimajorAxis;
    	double _meanAnomaly;
    	double _period;
    
    private:
    };
    
    class Astrum
    {
    public:
    
    	Astrum(double radius = 1, double mass = 1);
    
    	Astrum &setPosition(Vector position)
    	{
    		_position = position;
    		return *this;
    	}
    
    	virtual void draw(void);
    
    protected:
    
    	Vector _position;
    	double _radius;
    	double _mass;
    
    private:
    };
    
    class Star : public Astrum
    {
    public:
    
    	Star(double radius = 1, double mass = 1, double luminosity = 1) : 
    		Astrum(radius, mass),
    		_luminosity(luminosity)
    	{
    	}
    
    protected:
    
    	double _luminosity;
    
    private:
    };
    
    class Planet : public Astrum
    {
    public:
    
    	Planet(double radius = 1, double mass = 1, Orbit orbit = Orbit()) :
    		Astrum(radius, mass),
    		_orbit(orbit)
    	{
    	}
    
    	virtual void draw(double epoch = 0.0);
    	void drawOrbit(int segments = 30);
    
    	friend ostream &operator<<(ostream &os, Planet &p);
    
    protected:
    
    	Orbit _orbit;
    
    private:
    };
    
    }
    
    #endif
    I tried to comment everything above the Orbit class definition, leaving only the header guard and the namespace declaration, but to no good. If it helps, here is the contents of "vectors .h" too, but the error shouldn't be caused by that (it was issued even when "#include "vectors.h" was commented):
    Code:
    #ifndef __VECTORS_H__
    #define __VECTORS_H__ 1
    
    #include <vector>
    using std::vector;
    #include <ostream>
    using std::ostream;
    
    namespace math
    {
    
    enum Coordinate
    {
    	X,
    	Y,
    	Z,
    	K
    };
    
    class Vector
    {
    public:
    
    	Vector(int size);
    	Vector(double x, double y, double z);
    
    	double &operator[](const int dim)
    	{
    		return this->data.at(dim);
    	}
    
    	double operator*(Vector &b);
    	Vector &operator*=(double b);
    	Vector operator*(double b);
    	Vector &operator+=(Vector &b);
    	const Vector operator+(Vector &b);
    
    	double length(void);
    
    	friend ostream &operator<<(ostream &os, Vector &v);
    
    protected:
    
    	vector<double> data;
    
    private:
    };
    
    }
    
    #endif
    Thanks to everyone!
    I owe Paul McKenzie a pizza.

    I am no expert; but they say I can make concepts easy to understand. That's why newbies questions are mine!!! XD

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Unexpected tokens in a header

    You are missing one colon after the meanAnomaly parameter in your ctor´s parameter list.
    - Guido

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Unexpected tokens in a header

    Beaten to it...

  4. #4
    Join Date
    Jun 2007
    Location
    Vercelli, Italy
    Posts
    87

    Re: Unexpected tokens in a header

    So I could look above the ctor till the end of time! Thanks to both of you!
    I owe Paul McKenzie a pizza.

    I am no expert; but they say I can make concepts easy to understand. That's why newbies questions are mine!!! XD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured