Advertisement

Syntax Error?

Started by October 19, 2002 12:27 PM
9 comments, last by Tazel 22 years ago

  
struct velocity,position,acceleration {  //not sure if this type of declaration is valid

 int x;
 int y;
};

 


class ball {
 public:
  ball(position,velocity,accleration,friction);    //constructor

  velocity getVelocity() return vel;  //returns the current velocity

  velocity setVelocity(velocity);    //sets the velocity returns the previous velocity

  position getPosition() return pos;   //returns the current position

  position setPosistion(position);   //sets the position returns the previous position

  position update();   //updates the position returns the new position  *****acceleration and friction not factored in***

  /*
  acceleration getAccleration() return acc;   *******NOT IMPLEMENTED*********
  acceleration setAcceleration(accleration); *******NOT IMPLEMENTED*********
  int getFriction() return friction;   *******NOT IMPLEMENTED*********
  int setFriction(int);      *******NOT IMPLEMENTED*********
  */
 private:
  velocity vel;
  position pos;
  acceleration acc;
  int friction;
};

class paddle {
 public:
  paddle(position,velocity,width,height);  //constructor

};
  

ball::ball(position p, velocity v,acceleration a,int f) {
 pos.x = p.x;
 pos.y = p.y;
 vel.x = v.x;
 vel.y = v.y;
 acc.x = a.x;
 acc.y = a.y;
 friction = f;
}

velocity ball::setVelocity(velocity v) {
 velocity temp;
 temp.x = vel.x;
 temp.y = vel.y;
 vel.x = v.x;
 vel.y = v.y;
 return temp;
}

position ball::setPosition(position p) {
 position temp;
 temp.x = pos.x;  
 temp.y = pos.y;
 pos.x = p.x;
 pos.y = p.y;
 return temp;
}

position ball::update() {
 pos.x += vel.x;     //add x velocity

 pos.y += vel.y;  //add y velocity

 return pos;   //return new velocity

}
  
Errors: c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : error C2143: syntax error : missing '';'' before '','' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : error C2143: syntax error : missing '';'' before '','' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : error C2143: syntax error : missing '';'' before ''{'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : error C2447: missing function header (old-style formal list?) c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(11) : error C2629: unexpected ''class ball ('' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(11) : error C2238: unexpected token(s) preceding '';'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : error C2143: syntax error : missing '';'' before ''return'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : error C2059: syntax error : ''return'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : error C2238: unexpected token(s) preceding '';'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(14) : error C2146: syntax error : missing '';'' before identifier ''getPosition'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(14) : error C2501: ''position'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(14) : error C2143: syntax error : missing '';'' before ''return'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(14) : error C2059: syntax error : ''return'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(14) : error C2238: unexpected token(s) preceding '';'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(15) : error C2146: syntax error : missing '';'' before identifier ''setPosistion'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(15) : error C2501: ''position'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(15) : error C2061: syntax error : identifier ''position'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(16) : error C2146: syntax error : missing '';'' before identifier ''update'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(16) : error C2501: ''position'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(24) : error C2079: ''vel'' uses undefined struct ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(25) : error C2146: syntax error : missing '';'' before identifier ''pos'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(25) : error C2501: ''position'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(25) : error C2501: ''pos'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(26) : error C2146: syntax error : missing '';'' before identifier ''acc'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(26) : error C2501: ''acceleration'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(26) : error C2501: ''acc'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(32) : error C2629: unexpected ''class paddle ('' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(32) : error C2238: unexpected token(s) preceding '';'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2065: ''position'' : undeclared identifier c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2146: syntax error : missing '')'' before identifier ''p'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2350: ''ball::ball::ball'' is not a static member c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2059: syntax error : '')'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2143: syntax error : missing '';'' before ''{'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(36) : error C2447: missing function header (old-style formal list?) c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(46) : error C2027: use of undefined type ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : see declaration of ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(47) : error C2079: ''temp'' uses undefined struct ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(48) : error C2228: left of ''.x'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(48) : error C2228: left of ''.x'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(49) : error C2228: left of ''.y'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(49) : error C2228: left of ''.y'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(50) : error C2228: left of ''.x'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(50) : error C2027: use of undefined type ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : see declaration of ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(50) : error C2228: left of ''.x'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(51) : error C2228: left of ''.y'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(51) : error C2027: use of undefined type ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(1) : see declaration of ''velocity'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(51) : error C2228: left of ''.y'' must have class/struct/union type c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(55) : error C2039: ''setPosition'' : is not a member of ''ball'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(9) : see declaration of ''ball'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(55) : error C2146: syntax error : missing '';'' before identifier ''setPosition'' c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(55) : error C2501: ''position'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(55) : fatal error C1004: unexpected end of file found One of my programmers wrote this header file and it has some major syntax errors. I fixed some of them but I don''t know what some of them mean. Some help please? tcache Contact Me
Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
do it like this:


    typedef _coord{  int x;  int y;} velocity, position, acceleration;    


also your ball constructor makes no sense at all.
you have to supply types like in a normal function declaration (e.g. ball(int velocity...))

and you cant put a retun xy after a function declaration. use { } and put code between them.


Runicsoft -- home of my open source Function Parser and more

[edited by - Burning_Ice on October 19, 2002 1:43:07 PM]
Advertisement
What''s the _coord for? An abbreviation for coordinates?

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
(Updated)

  typedef coordinates; {   int x; int y;}int velocity, position, acceleration;class ball { public:  ball(position,velocity,accleration,friction);    //constructor  velocity getVelocity() {return vel;}  //returns the current velocity  velocity setVelocity(int velocity);    //sets the velocity returns the previous velocity  position getPosition() {return pos;}   //returns the current position  position setPosistion(int position);   //sets the position returns the previous position  position update();   //updates the position returns the new position  *****acceleration and friction not factored in***  /*  acceleration getAccleration() return acc;   *******NOT IMPLEMENTED*********  acceleration setAcceleration(accleration); *******NOT IMPLEMENTED*********  int getFriction() return friction;   *******NOT IMPLEMENTED*********  int setFriction(int);      *******NOT IMPLEMENTED*********  */ private:  velocity vel;  position pos;  acceleration acc;  int friction;};class paddle { public:  paddle(position,velocity,width,height);  //constructor};  ball::ball(position p, velocity v,acceleration a,int f) { pos.x = p.x; pos.y = p.y; vel.x = v.x; vel.y = v.y; acc.x = a.x; acc.y = a.y; friction = f;}velocity ball::setVelocity(velocity v) { velocity temp; temp.x = vel.x; temp.y = vel.y; vel.x = v.x; vel.y = v.y; return temp;}position ball::setPosition(position p) { position temp; temp.x = pos.x;   temp.y = pos.y; pos.x = p.x; pos.y = p.y; return temp;}position ball::update() { pos.x += vel.x;     //add x velocity pos.y += vel.y;  //add y velocity return pos;   //return new velocity}  


Still 33 errors. A couple of them:

c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(4) : error C2447: missing function header (old-style formal list?)
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(11) : error C2629: unexpected ''class ball (''
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(11) : error C2238: unexpected token(s) preceding '';''
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : error C2146: syntax error : missing '';'' before identifier ''getVelocity''
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : error C2501: ''velocity'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(12) : warning C4183: ''getVelocity'': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\x-cellsoft\pongcollision\objectclass.h(13) : error C2146: syntax error : missing '';'' before identifier ''setVelocity''

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
sorry i forgot struct after the typedef in the above code.

_coords is just some arbitrary structname

to correct your errors:

1) learn how to declare a struct
sorry, but the ; after the typedef coordinates is just wrong there, also what''s with the int after the struct declaration?

2) as i said, constructors are function and need to have type and variablename information
make it
ball(position p,velocity v,acceleration a,int f);
same goes for the paddle class

3) you have a typo in your setPosition function

4) in the class declaration you have setVelocity(int velocity) and in the definition its setVelocity (velocity v)
they have to be the same...

for your convenience i just corrected the code for you :


  typedef struct _coordinates {   int x; int y;} velocity, position, acceleration;class ball { public:  ball(position p,velocity v,acceleration a,int f);    //constructor  velocity getVelocity() {return vel;}  //returns the current velocity  velocity setVelocity(velocity v);    //sets the velocity returns the previous velocity  position getPosition() {return pos;}   //returns the current position  position setPosition( position p);   //sets the position returns the previous position  position update();   //updates the position returns the new position  *****acceleration and friction not factored in***  /*  acceleration getAccleration() return acc;   *******NOT IMPLEMENTED*********  acceleration setAcceleration(accleration); *******NOT IMPLEMENTED*********  int getFriction() return friction;   *******NOT IMPLEMENTED*********  int setFriction(int);      *******NOT IMPLEMENTED*********  */ private:  velocity vel;  position pos;  acceleration acc;  int friction;};class paddle { public:  paddle(position p,velocity v, int width, int height);  //constructor};  ball::ball(position p, velocity v,acceleration a,int f) { pos.x = p.x; pos.y = p.y; vel.x = v.x; vel.y = v.y; acc.x = a.x; acc.y = a.y; friction = f;}velocity ball::setVelocity(velocity v) { velocity temp; temp.x = vel.x; temp.y = vel.y; vel.x = v.x; vel.y = v.y; return temp;}position ball::setPosition(position p) { position temp; temp.x = pos.x;   temp.y = pos.y; pos.x = p.x; pos.y = p.y; return temp;}position ball::update() { pos.x += vel.x;     //add x velocity pos.y += vel.y;  //add y velocity return pos;   //return new velocity}  





Runicsoft -- home of my open source Function Parser and more
For one, your setVelocity() is expecting 2 different things without. In the class it says: setVelocity(int velocity) (btw, that makes no sense). And in the implementation it says: setVelocity(velocity v). Well, it can''t be both so you gotta choose one and stick with it. I''m betting the velocity v is the correct choice though

In the constructor''s argument list give the variables some kind of name, instead of just the type and it should stop complaining about the first 4 errors. And give friction a type (most likely an int or a float)


  typedef struct Coordinates{  int x;  int y;} position, velocity, acceleration;  


No int after the typedef is needed.

That should clear up some errors at least.

I''m learning, just like the best of us...

Ok, now assume a spherical cow...
I'm learning, just like the best of us...Ok, now assume a spherical cow... :)
Advertisement
Oh, I see. Thanks Burning_Ice.

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)

  typedef struct coordinates {   	int x; 	int y;}velocity, position, acceleration;class ball {	public:  		ball(position p,velocity v,acceleration a,int f);  //constructor  		velocity getVelocity() {return vel;}  //returns the current velocity  		velocity setVelocity(velocity v);    //sets the velocity returns the previous velocity  		position getPosition() {return pos;}   //returns the current position  		position setPosition( position p);   //sets the position returns the previous position  		int Collision_Detection();		position update();   //updates the position returns the new position  *****acceleration and friction not factored in***  		/*  acceleration getAccleration() return acc;   *******NOT IMPLEMENTED*********  		acceleration setAcceleration(accleration); *******NOT IMPLEMENTED*********  		int getFriction() return friction;   *******NOT IMPLEMENTED*********  		int setFriction(int);      *******NOT IMPLEMENTED*********  		*/ 	private:  		velocity vel;  		position pos;		position ballpos;		acceleration acc;  		int friction;};class paddle { 	public:  		paddle(position p,velocity v, int width, int height);  //constructor                int leftpaddle;		int rightpaddle;};  ball::ball(position p, velocity v,acceleration a,int f) { 	pos.x = p.x; 	pos.y = p.y; 	vel.x = v.x; 	vel.y = v.y; 	acc.x = a.x; 	acc.y = a.y; 	friction = f;}velocity ball::setVelocity(velocity v) { 	velocity temp; 	temp.x = vel.x; 	temp.y = vel.y; 	vel.x = v.x; 	vel.y = v.y; 	return temp;}position ball::setPosition(position p) { 	position temp; 	temp.x = pos.x;   	temp.y = pos.y; 	pos.x = p.x; 	pos.y = p.y; 	return temp;}position ball::update() { 	pos.x += vel.x;     //add x velocity 	pos.y += vel.y;  //add y velocity 	return pos;   //return new velocity}int ball::Collision_Detection() /**The collision detection code**/{	if(ballpos >= rightpaddle)	{		ballpos=ballpos-1;	}	else if(ballpos <= rightpaddle)	{		ballpos=ballpos+1;	} 	else if(ballpos <= leftpaddle)	{		ballpos=ballpos+1;	}	else if(ballpos >= leftpaddle)	{		ballpos=ballpos-1;	}	/*Simple mainframe of the collision detection.  I haven''t been able to write a complete one yet	because of lack of information on class variables, etc.*/}  


Could you guys tell me why that the >= and all those conditional operators be a problem? Also, anything wrong with the collision detection code?

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Some questions to ask re: your design:

ballpos is of type position and a member variable of the class ball?

rightpaddle and leftpaddle are of type int and are member variables of the class paddle?

How does the ball class''s Collision function know about the paddles? Where are the paddle variables that the ball class has access to? Should the ball class know about the paddles?

Should the paddles know about the ball?

Why does the paddle class declare 2 paddle variables? What is each one for? What exactly is the purpose of the paddle class?
Sorry, I wasn''t thinking very well. I have no idea why they''re like that.

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)

This topic is closed to new replies.

Advertisement