C++ 结构 - 错误 1 错误 C2143:语法错误:缺少'*'之前的';'
C++ Struct - Error 1 error C2143: syntax error : missing ';' before '*'
当我尝试编译以下内容时,我收到错误"错误 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_vert
和HE_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_vert
和HE_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>
};
拉兹万。
相关文章:
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- C++语法头文件错误
- 如何摆脱错误c2061;语法错误 cout?
- 语法错误:D3DX10Core 中的标识符'TEXTMETRICA'
- 错误 C2146:语法错误:标识符"A1"之前缺少","
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- RedisGraph 语法错误在偏移量 8 靠近"创建"
- 如何修复此 FSM C++语法错误 C3867
- 函数错误 C2059:语法错误:'>'不起作用
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- system() 返回错误语法错误:"("意外
- C++图形初始化错误(语法或丢失文件缺陷?
- 获取0:1(1):错误:语法错误,尝试编译着色器时意外$end
- Visual Studio错误:语法错误:标识符