开发者

expected constructor, destructor, or type conversion before ‘.’ token

BALL ball1;//,ball2,ball3;
ball1.bx = 0;
ball1.by = 0;
ball1.bvx = 1.0;
ball1.bvy = 1.0;
ball1.radius = 5.0;

BALL is a struct in a separate.h file where I have used the following code :

typedef struct ball
{
 GLfloat bx;
 GLfloat by;
 GLfloat bvx;
 GLfloat bvy;
 GLfloat radius;

}BALL;

typedef struct paddle
{
 GLfloat length;
 GLfloat width;
 GLfloat px;
 GLfloat py;开发者_如何学Python
 GLfloat pvx;
 GLfloat pvy;
 bool alongX;
}PADDLE;

But in the main file I am getting the above error !

The code in the main file is :

#include "header.h"
#include "ball_pad.h"
#include "pingpong.h"
#include "texture.h"
#include "3dsloader.h"


float A = 45.0f,AA = -45.0f;
float B = 35.0f,BB = -35.0f;
/**********************************************************
 *
 * VARIABLES DECLARATION
 *
 *********************************************************/

// The width and height of your window, change them as you like
int screen_width=640;
int screen_height=480;

// Absolute rotation values (0-359 degrees) and rotation increments for each frame
double rotation_x=0, rotation_x_increment=0.1;
double rotation_y=0, rotation_y_increment=0.05;
double rotation_z=0, rotation_z_increment=0.03;

// Absolute rotation values (0-359 degrees) and rotation increments for each frame
double translation_x=0, translation_x_increment=1.0;
double translation_y=0, translation_y_increment=0.05;
double translation_z=0, translation_z_increment=0.03;

// Flag for rendering as lines or filled polygons
int filling=1; //0=OFF 1=ON

//Now the object is generic, the cube has annoyed us a little bit, or not?
obj_type board,ball,pad_alongX,pad_alongY;

BALL ball1;//,ball2,ball3;
ball1.bx = 0;
ball1.by = 0;
ball1.bvx = 1.0;
ball1.bvy = 1.0;
ball1.radius = 5.0;


As the code would be valid if it occurred within a function, I am assuming that it occurs outside any function.

The ball1.XXX = YYY; lines are all assignment statements and these may only occur within a function.

If you want to initialise the ball1 object with a certain set of values, you can do it like this:

BALL ball1 = { 0, 0, 1.0, 1.0, 5.0 };

or, if your compiler supports it:

BALL ball1 = { .bx = 0, .by = 0, .bvx = 1.0, .bvy = 1.0, .radius = 5.0 };


You'll have to post more code in order for someone to tell you exactly where the problem lies. Many times this error is due to some syntax error such as not putting a semi-colon at the end of a class (possibly GLfloat?), to not specifying a namespace in front of an object you're trying to create or use. Also, make sure you have all necessary includes in your source file.

You can try and prune down the code and compile to see when it's successful and then work back forward from that point. Here I would begin by commenting out all the GLfloat members of the struct and any code that relies on them and compile. Continue pruning until you've scoped down to the problem file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜