C 在‘;之前需要构造函数、析构函数或类型转换’;代币

C 在‘;之前需要构造函数、析构函数或类型转换’;代币,c,struct,C,Struct,BALL是一个单独的.h文件中的结构,我在其中使用了以下代码: BALL ball1;//,ball2,ball3; ball1.bx = 0; ball1.by = 0; ball1.bvx = 1.0; ball1.bvy = 1.0; ball1.radius = 5.0; 但是在主文件中,我得到了上面的错误 主文件中的代码是: typedef struct ball { GLfloat bx; GLfloat by; GLfloat bvx; GLfloat bvy; GLf

BALL是一个单独的.h文件中的结构,我在其中使用了以下代码:

BALL ball1;//,ball2,ball3;
ball1.bx = 0;
ball1.by = 0;
ball1.bvx = 1.0;
ball1.bvy = 1.0;
ball1.radius = 5.0;
但是在主文件中,我得到了上面的错误

主文件中的代码是:

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;

您必须发布更多代码,以便有人准确地告诉您问题所在。很多时候,这个错误是由于一些语法错误造成的,比如没有在类的末尾放分号(可能是GLfloat?),或者没有在试图创建或使用的对象前面指定名称空间。另外,确保源文件中包含了所有必要的include


您可以尝试删减代码并进行编译,以查看它何时成功,然后从这一点开始向前工作。在这里,我将首先注释掉结构的所有GLfloat成员以及依赖于它们的任何代码,然后进行编译。继续修剪,直到您确定了问题文件的范围。

您必须发布更多代码,以便有人准确地告诉您问题所在。很多时候,这个错误是由于一些语法错误造成的,比如没有在类的末尾放分号(可能是GLfloat?),或者没有在试图创建或使用的对象前面指定名称空间。另外,确保源文件中包含了所有必要的include

您可以尝试删减代码并进行编译,以查看它何时成功,然后从这一点开始向前工作。在这里,我将首先注释掉结构的所有GLfloat成员以及依赖于它们的任何代码,然后进行编译。继续修剪,直到您确定了问题文件的范围。

因为如果代码发生在函数中,则代码是有效的,所以我假设它发生在任何函数之外

ball1.XXX=YYY行都是赋值语句,它们只能出现在函数中

如果要使用特定的值集初始化
ball1
对象,可以这样做:

#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;
或者,如果您的编译器支持:

BALL ball1 = { 0, 0, 1.0, 1.0, 5.0 };
由于如果代码发生在函数内,则该代码是有效的,因此我假设它发生在任何函数外

ball1.XXX=YYY行都是赋值语句,它们只能出现在函数中

如果要使用特定的值集初始化
ball1
对象,可以这样做:

#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;
或者,如果您的编译器支持:

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

ObjyType是在哪里声明和定义的?ObjyType是在哪里声明和定义的?你把问题标记为C,但是你的错误消息是C++。因此,第一件事是为代码使用正确的编译器(或更改标记)。第二,你给我们列出代码并给出错误消息,但不告诉我们它发生在哪一行是没有意义的。然后,也许只给我们你的平台设置(OS,编译器,编译器选项)。你把问题标记为C,但是你的错误消息是C++。因此,第一件事是为代码使用正确的编译器(或更改标记)。第二,你给我们列出代码并给出错误消息,但不告诉我们它发生在哪一行是没有意义的。然后,也许只需给我们您的平台设置(操作系统、编译器、编译器选项)。