When compiling this code on VS2008:
#include <vector>
using namespace std;
class Vertex {
public: double X;
double Y;
double Z;
int id; // place of vertex in original mesh vertex list
vector<Vertex*> neighbor; //adjacent vertices
vector<Triangle*> face; // adjacent triangles
float cost; // saved cost of collapsing edge
Vertex *collapse; //
};
class Triangle {
public:
Vertex * vertex[3];
};
I get the following error:
1>.\Triangle.cpp(15) : error C2065: 'Triangle' : undeclared identifier
How can I fix this?
You use a forward declaration:
A forward declaration of a type (e. g.
class Triangle) allows you to declare pointers or references to that type, but not objects of the type. In other wordswill compile, but
will not compile.
Also, a forward declaration of a type does not let you access its members, because the compiler does not know about them yet. So the member functions that use objects of the forward declared type must be defined after the type is fully defined. In your case, after the definition of
class Triangle.Oh, and this is not at all specific to Visual Studio. This is just standard C++.