C++ 结构 - 错误 1 错误 C2143:语法错误:缺少'*'之前的';'

C++ Struct - Error 1 error C2143: syntax error : missing ';' before '*'

本文关键字:错误 语法 结构 C2143 C++ 缺少      更新时间:2023-10-16

当我尝试编译以下内容时,我收到错误"错误 1 错误 C2143:语法错误:在"*"之前缺少';"。有谁知道为什么我会收到此错误?我在这里做错了什么?

struct HE_edge {
HE_vert* vert; // vertex at the end of the half-edge<br>
HE_edge* pair; // oppositely oriented half-edge<br>
HE_face* face; // the incident face<br>
HE_edge* prev; // previous half-edge around the face<br>
HE_edge* next; // next half-edge around the face<br>
};
struct HE_vert {
float x, y, z; // the vertex coordinates<br>
HE_edge* edge; // one of the half-edges emanating from the vertex<br>
};
struct HE_face {
HE_edge* edge; // one of the half-edges bordering the face<br>
};

尝试以正确的顺序声明您的结构:由于HE_edge取决于HE_vert和HE_face,因此请先声明它们。

struct HE_vert;
struct HE_face;
struct HE_edge {
HE_vert* vert; // vertex at the end of the half-edge<br>
HE_edge* pair; // oppositely oriented half-edge<br>
HE_face* face; // the incident face<br>
HE_edge* prev; // previous half-edge around the face<br>
HE_edge* next; // next half-edge around the face<br>
};
struct HE_vert {
float x, y, z; // the vertex coordinates<br>
HE_edge* edge; // one of the half-edges emanating from the vertex<br>
};
struct HE_face {
HE_edge* edge; // one of the half-edges bordering the face<br>
};

HE_edge中使用它们之前,您需要转发声明HE_vertHE_face

// fwd declarations. Can use "struct" or "class" interchangeably.
struct HE_vert;
struct HE_face;
struct HE_edge { /* as before */ };

请参阅何时使用前向声明?

在使用它们的类型进行指针之前,您需要声明所有类:

struct HE_edge;
struct HE_vert;
struct HE_face;
// your code
在使用

标识符之前,必须声明标识符。对于结构,只需通过例如

struct HE_vert;

将其放在HE_edge的定义之前。

第一个声明不知道HE_vertHE_face是什么,你需要告诉编译器这些是什么:

struct HE_face;
struct HE_vert;//tell compiler what are HE_vert and HE_face
struct HE_edge {
HE_vert* vert; // vertex at the end of the half-edge<br>
HE_edge* pair; // oppositely oriented half-edge<br>
HE_face* face; // the incident face<br>
HE_edge* prev; // previous half-edge around the face<br>
HE_edge* next; // next half-edge around the face<br>
};
struct HE_vert {
float x, y, z; // the vertex coordinates<br>
HE_edge* edge; // one of the half-edges emanating from the vertex<br>
};
struct HE_face {
HE_edge* edge; // one of the half-edges bordering the face<br>
};

拉兹万。