1

当我尝试编译以下内容时,我收到错误“错误 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>
};
4

5 回答 5

4

尝试以正确的顺序声明您的结构:由于 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>
};
于 2013-10-09T08:33:30.053 回答
2

您需要在使用它们之前转发声明HE_vert和。HE_faceHE_edge

// fwd declarations. Can use "struct" or "class" interchangeably.
struct HE_vert;
struct HE_face;

struct HE_edge { /* as before */ };

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

于 2013-10-09T08:30:09.123 回答
1

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

struct HE_edge;
struct HE_vert;
struct HE_face;

// your code
于 2013-10-09T08:30:24.433 回答
1

您必须在使用标识符之前声明它们。对于结构,这只需通过例如

struct HE_vert;

把它放在 的定义之前HE_edge

于 2013-10-09T08:30:34.353 回答
1

第一个声明不知道是什么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>
};

拉兹万。

于 2013-10-09T08:32:06.780 回答