c - ‘.’ 标记之前的预期构造函数、析构函数或类型转换

标签 c struct

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/

相关文章:

c++ - udp源端口和目的端口必须匹配吗?

C : Deleting only one node from a doubly linked list

c - 结构指针数组和分配结构数据

将结构复制到另一个结构的成员

c++ - 如何在类中定义枚举并从外部使用它

c - C-使用read()和write()从一个文件复制到另一个文件,而不使用文件功能

c - C 中 float 组的 Memset 问题

c - 为什么 gcc 忽略 'register' 对一个 int 变量的请求并接受另一个 int 变量的请求

c - 这个值是如何计算的?

c++ - 结构初始化语法