C ++ Struct - 错误1错误C2143:语法错误:缺少';'在'*'之前

时间:2013-10-09 08:27:54

标签: c++ struct

当我尝试编译以下内容时,我收到错误"错误1错误C2143:语法错误:丢失&#39 ;;'之前' *'"。有谁知道为什么我收到这个错误?我在这做错了什么?

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>
};

5 个答案:

答案 0 :(得分: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>
};

答案 1 :(得分: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 */ };

请参阅When to use forward declaration?

答案 2 :(得分:1)

在使用类型生成指针之前,需要声明所有类:

struct HE_edge;
struct HE_vert;
struct HE_face;

// your code

答案 3 :(得分:1)

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

完成的
struct HE_vert;

将其放在HE_edge的定义之前。

答案 4 :(得分: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>
};

勒兹。