G 将函数返回struct的原型混淆为结构初始化器

G++ confuses prototype of function returning struct as struct initializer

本文关键字:结构 初始化 原型 函数 返回 struct      更新时间:2023-10-16

编译项目时,我会收到以下错误:

drawplant.h: In function 'Matrix3f current_matrix()':
drawplant.h:26:1: error: only constructors take member initializers
 Matrix3f mmmult(Matrix3f, Matrix3f);

这是drawplant.h:

#ifndef _DRAWPLANT_H_
#define _DRAWPLANT_H_
/* Functions implemented in drawplant.cpp */
#define PI 3.14159265358

struct Vector3f{
    GLdouble v[4];
} typedef Vector3f;
struct Matrix3f{
    GLdouble m[16];
} typedef Matrix3f;
extern int depth;
void drawPlant();
void push();
void pop();
//void rotate(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
//void translate(GLdouble, GLdouble, GLdouble);
//void scale(GLdouble, GLdouble, GLdouble);
Matrix3f current_matrix(void):
Matrix3f mmmult(Matrix3f, Matrix3f);
Vector3f mvmult(Matrix3f, Vector3f);
#endif  /* _DRAWPLANT_H_ */

尝试更改

Matrix3f current_matrix(void):

to

Matrix3f current_matrix(void);

请注意末尾的分号。