Including

Started by
3 comments, last by Fruny 18 years ago
I'm working with dev and suddenly something stopped working, I have a file "Selection.h" that looke like this:

#ifndef SELECTION_H
#define SELECTION_H

#include <vector>
#include <algorithm>
#include "3DMath.h"
#include "Terrain.h"
#include "BSP.h"

using namespace std;
//NOT IMPORTANT PART
struct SPlane{
 CVector3 v_Corners[4];
 int ID;
 //SPlane();
 //SPlane(vector<CVector3> c){v_Corners = c;}
 //SPlane(vector<CVector3> c, int i){v_Corners = c; ID = i;}
};

struct SBox{
 SPlane v_Sides[6];
 int ID;
 //SBox(vector<SPlane> s, int i){v_Sides = s; ID = i;}
 SBox(float x, float y, float z, float w, float d, float h, int i);
 void InitBox(float x, float y, float z, float w, float d, float h, int i);
 //for debugging only
 void DrawBox();
};
//IMPORTANT PART
struct SPickedArea2{
 
 float centerX, centerZ;
 float width, depth;
 float distance;
 CVector3 vLine[2];
 BYTE* p_HeightMap;
 SPickedArea2(float x, float z, float w, float d, CVector3 line[], BYTE *pH); 
 void GetDistanceForArea();
 bool hit;
 friend bool operator<(const SPickedArea2& lhs, const SPickedArea2& rhs)
	{
		return ( lhs.distance < rhs.distance );
	}
};
       

bool SelectBoxWithRay(SBox& Boxes, CVector3 line[]);
void RenderTriangle(CVector3 v_Triangle[]);

#endif    
  

and a file BSP.h that looks like this:

#ifndef BSP_H
#define BSP_H

#include <gl\gl.h>
#include <vector>
#include "Terrain.h"
#include "CCamera.h"
#include "NeHe.h"
#include "Selection.h"
using namespace std;
//NOT IP
struct BSP{
 float height, width, depth;
 float centerX, centerY, centerZ;
 MinMax limits;
 BSP *p_sec1, *p_sec2, *p_sec3, *p_sec4;
 bool found_limits;
 bool is_leaf;
 bool picked;
};

class CBspTree{
 public: 
   CBspTree();
  ~CBspTree();
   int number_of_parts;
   void GetHeightMap(BYTE *pH){p_HeightMap = pH;}
   void GetBoxes(){map->limits = FindLimits(map);}
   void RenderMap();
   VERTEX PickedCenter;
   void Picking(CVector3 line[]);
 private:
   BSP* map;
   BYTE* p_HeightMap;
   bool color;
   void InitTree(BSP* node, float x, float y, float h, float w);
   void EraseBSP(BSP* node);
   void Render(BSP* node);
   void PickCenter(BSP* node);
   CVector3 v_Line[2];
   MinMax FindLimits(BSP* node);
   MinMax FindLimitsOfArea(float blX, float blY, float trX, float trY);
   //IP
   vector<SPickedArea2> Areas;
};



#endif


When I tried to compile I got the error: 43 C:\Dev-Cpp\Examples\height2\BSP.h `SPickedArea2' was not declared in this scope But I included it? I tried to rebuild and kept on getting this? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
Since Selection.h includes BSP.h before declaring SPickedArea2, which BSP.h needs, the error is not surprising. The re-inclusion of Selection.h within BSP.h is (correctly!) nullified by its header guards.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Selection.h includes BSP.h, which is equivalent to copying the source inside BSP.h and pasting at the #include "BSP.h" line int Selection.h. Obviously if you do this the definition of CBspTree will stand above the definition of SPickedArea2, so SPickedArea2 is still undefined.

Read this article :)

EDIT: Beaten ;)
_______________The essence of balance is detachment. To embrace a cause, to grow fond or spiteful, is to lose one''s balance after which, no action can be trusted. Our burden is not for the dependent of spirit. - Mayar, Third Keeper
I read the article. So to solve the problem should I use forward declaration? -In the Selection.h file I should write struct BSP; instead of #include "BSP.h"?
Is that right?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Yes, so long as you keep in mind that an incomplete type (a type that has been declared but not defined) is strictly restricted as to how it can be used. You cannot use it in any place that would require knowing its size, or actually making use of the definition in any way (duh!). That means you can use it to declare functions, but not to define them. You can define references or pointers to an incomplete type, but not actual variables of that type -- nor member variables, since you would need the size of the member to compute the size of the class that contains it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement