BALL ball1;//,ball2,ball3;
ball1.bx = 0;
ball1.by = 0;
ball1.bvx = 1.0;
ball1.bvy = 1.0;
ball1.radius = 5.0;
BALL 是 separate.h 文件中的一个结构,我在其中使用了以下代码:
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;
GLfloat pvx;
GLfloat pvy;
bool alongX;
}PADDLE;
但是在主文件中我得到了上面的错误!
主文件中的代码是:
#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;
最佳答案
如果代码出现在函数内,那么我假设它出现在任何函数外。
ball1.XXX = YYY;
行都是赋值语句,它们只能出现在一个函数中。
如果你想用一组特定的值初始化 ball1
对象,你可以这样做:
BALL ball1 = { 0, 0, 1.0, 1.0, 5.0 };
或者,如果你的编译器支持的话:
BALL ball1 = { .bx = 0, .by = 0, .bvx = 1.0, .bvy = 1.0, .radius = 5.0 };
关于c - ‘.’ 标记之前的预期构造函数、析构函数或类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3923270/