Forward declaration error


Dear Users,,

I am using OpenCASCADE environment to read STL file! Well the problem with c++ knowledge!!
I face a problem, with forward declaration error with the following

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
void StlReadIn::STL_Import()
{

	          std::string FileName;
	          std::cout<<"\nEnter the file name\n";
                  std::cin>>FileName;
	          OSD_Path aFile(FileName.c_str());
		     Standard_Boolean ReturnValue = Standard_True;

		     Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
		     TopoDS_Compound ResultShape;
		     BRep_Builder CompoundBuilder;
		     CompoundBuilder.MakeCompound(ResultShape);

		     Standard_Integer NumberDomains = aSTLMesh->NbDomains(); // The error shows here
		     Standard_Integer iND;
		     gp_XYZ p1, p2, p3;
		     TopoDS_Vertex Vertex1, Vertex2, Vertex3;
		     TopoDS_Face AktFace;
		     TopoDS_Wire AktWire;
		     BRep_Builder B;
		     Standard_Real x1, y1, z1;
		     Standard_Real x2, y2, z2;
		     Standard_Real x3, y3, z3;

		     StlMesh_MeshExplorer aMExp (aSTLMesh);

		//     BRepBuilderAPI_MakeWire WireCollector;
		     for (iND=1;iND<=NumberDomains;iND++)
		     {
		          for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
		          {
		               aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
		               p1.SetCoord(x1,y1,z1);
		               p2.SetCoord(x2,y2,z2);
		               p3.SetCoord(x3,y3,z3);

		               if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
		               {
		                    Vertex1 = BRepBuilderAPI_MakeVertex(p1);
		                    Vertex2 = BRepBuilderAPI_MakeVertex(p2);
		                    Vertex3 = BRepBuilderAPI_MakeVertex(p3);

		                    AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);

		                    if( !AktWire.IsNull())
		                    {
		                         AktFace = BRepBuilderAPI_MakeFace( AktWire);
		                         if(!AktFace.IsNull())
		                              CompoundBuilder.Add(ResultShape,AktFace);
		                    }
		               }
		          }
		     }
		     TopoDS_Shape aShape = ResultShape;
}


Error message:

stlreadin.cpp:26:47: error: invalid use of incomplete type ‘struct StlMesh_Mesh’
/usr/local/oce-0.9.1/include/oce/Handle_StlMesh_Mesh.hxx:23:7: error: forward declaration of ‘struct StlMesh_Mesh’



Please suggestion, and correction! I am sorry but, i do not understand the problem and the meaning of the message!

Hope to receive ur comments
Thank you very much for the help

Game
A forward declaration is where you declare that something is a class or a struct, but don't provide the full definition of that class/struct. It allows you to declare pointers or references to a type, but you can't use them in any way that needs to know the definition. So, for example, you can have:

1
2
3
4
5
6
7
8
9
10
11
12
13
class A;  // Forward declaration

class B
{
public: 
  B(); // Constructor

  MyFunc(A* ptr_to_object_of_type_a);  // Only using a pointer to A

private:

  A* m_another_pointer_to_object_of_type_a;  // Only using a pointer to A
};


But you can't have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A;  // Forward declaration

class B
{
public: 
  B(); // Constructor

  MyFunc(A* ptr_to_object_of_type_a)
  {
    ptr_to_object_of_type_a->AnotherFunc();  // Attempting to dereference the pointer to call a method
  }

private:

  A m_object_of_type_a;  // Declaring an object of type A 


In the second version, you'd have to include the full definition of A, most likely from a header file.

What your error message means is that in /usr/local/oce-0.9.1/include/oce/Handle_StlMesh_Mesh.hxx, which you've included, there is a forward declaration to the structure StlMesh_Mesh, but somewhere in your code, there's something that needs to know the full definition of it, and you haven't included the header file that contains that full definition.
Last edited on

Thank you very much Mikeyboy,

Thank you very much for nice and clear explanation, You helped me out!

Using your comment, i solved the problem adding #include <StlMesh_Mesh.hxx> header file!

Working,, thank you once again

Game
Topic archived. No new replies allowed.