• Advertisement
Sign in to follow this  


This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working with dev and suddenly something stopped working, I have a file "Selection.h" that looke like this:

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

using namespace std;
struct SPlane{
 CVector3 v_Corners[4];
 int ID;
 //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();
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[]);


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;
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{
   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[]);
   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);
   vector<SPickedArea2> Areas;


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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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 ;)

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement