1

when i try to compile the following, i receive the error "Error 1 error C2143: syntax error : missing ';' before '*'". Does anyone know why am i receiving this error? What am i doing wrong here?

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>
};
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
Cherple
  • 725
  • 3
  • 10
  • 24
  • You need your declarations in the opposite order. `HE_edge` tries to use `HE_vert`, which the compiler doesn't know about yet. – BoBTFish Oct 09 '13 at 08:30
  • 1
    ho forward declaration of you types ? So HE_vert does not name a type in the definition of HE_edge. A lot of compiler tell you this now, apparently not yours. – Jaffa Oct 09 '13 at 08:30
  • In fact, I didn't immediately realise you have a circular dependency. Look at [forward declarations](http://stackoverflow.com/q/553682/1171191). – BoBTFish Oct 09 '13 at 08:32

5 Answers5

4

Try to declare your structs in the right order : Since HE_edge depends on HE_vert and HE_face, declare them before.

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>
};
Thomas Benard
  • 200
  • 1
  • 3
  • 10
2

You need to forward declare HE_vert and HE_face before you use them in HE_edge.

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

struct HE_edge { /* as before */ };

See When to use forward declaration?

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
1

You need to declare all the classes before you use their types to make pointers:

struct HE_edge;
struct HE_vert;
struct HE_face;

// your code
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
1

You must declare identifiers before you use them. For structures this is simply done by e.g.

struct HE_vert;

Place that before the definition of HE_edge.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
1

The first declaration has no idea what HE_vert and HE_face is, to you need to tell the compiler what are those:

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

Razvan.

Raxvan
  • 6,257
  • 2
  • 25
  • 46