[solved] 'member' is not a type request for member of non-aggre...

Started by
2 comments, last by Zahlman 13 years, 12 months ago
edit: this problem is solved, I am now asking for help here. I can't understand why my compiler is throwing these errors:
Quote: In member function `env_cell* env_cell::findCell(float, float)': 'right' is not a type
(likewise for left, top and bottom) Here is my class:

//individual cell in the environment
class env_cell{
  public:
  float top,left,bottom,right;
  int id;
  CheightMap heightMap; //height map
  env_map* map; //pointer to map handler object
  std::vector<env_cell*> visCells; //cells that can be seen from this cell
  std::vector<env_cell*>::iterator visCellsI; //visible cells iterator
  GLuint opaqueDraw, transDraw; //compiled static mesh and bsp display lists
  std::vector<entity*> entities; //pointers to entities within the cell
  prop_static staticProps[]; //static props linked to the cell
  bsp_detail detail[]; //bsp geometry linked to the cell cell
  std::vector<light*> lights; //pointers to lights in the cell
  float startHeight; //starting z height from z = 0
  int nextVisCellPos,nextStaticProp,nextBsp,nextLight;
  
  //constructor
  env_cell(int sId,float sTop,float sLeft,float sBottom,float sRight){
    id = sId;
    top = sTop;
    left = sLeft;
    bottom = sBottom;
    right = sRight;
    opaqueDraw = glGenLists(1);
    transDraw = glGenLists(1);
  }
  
  //set the height map and z start
  void setHeight(CheightMap sHeightMap,float sStartHeight){
    heightMap = sHeightMap;
    startHeight = sStartHeight;
  }
  
  //adds a cell pointer to the array of cells this cell can see
  void addVisCell(env_cell* visCell){
    visCells.push_back(visCell);
    nextVisCellPos ++;
  }
  
  //adds a static prop to the cell
  void addStaticProp(prop_static prop){
    staticProps[nextStaticProp] = prop;
    nextStaticProp ++;
  }
  
  //adds some bsp geometry to the cell
  void addBspDetail(bsp_detail bsp){
    detail[nextBsp] = bsp;
    nextBsp ++;
  }
  
  //renders the static props and bsp detail into display lists
  void compileDispLists(){
    //make opaque & transparent geometry into display lists
    
    //build opaque geometry
    glNewList(opaqueDraw,GL_COMPILE);
      //just draw a floor now (rather than combine static props and bsp)
    	glBegin(GL_QUADS);
    		//glNormal3f(0,1,0); //up
    		glVertex3f(left,0,bottom);
    		glVertex3f(right,0,bottom);
    		glVertex3f(right,0,top);
    		glVertex3f(left,0,top);
    	glEnd();
  	glEndList();
  }
  //what about light maps?
  
  //add a pointer to a light within the cell
  void addLight(light * thisLight){
    lights.push_back(thisLight);
    nextLight ++;
  }
  
  //returns the pointer of the cell a position is in
  env_cell* findCell(float x,float z){
    env_cell * foundCell;
    for(visCellsI = visCells.begin();visCellsI != visCells.end();visCellsI++){
      //if point is inside the cell
      if(x<=visCellsI->right && x>=visCellsI->left && z<=visCellsI->top && 
      z>=visCellsI->bottom){ //THIS LINE
        foundCell = &(*visCellsI);
        break;
      }
    }
    
    //if a cell was found
    if(foundCell){
      return foundCell; //return new cell
    } else {
      return this; //keep current cell assigned
    }
  }
};



(errors thrown on line commented "THIS LINE")

if(x<=visCellsI->right && x>=visCellsI->left && z<=visCellsI->top && z>=visCellsI->bottom)



I don't see why It can't find the members. There is another point where the same logic is processed (finding a cell pointer on the whole map not just adjacent cells to a given cell), also throwing errors. Ask for any more info because I don't know what else to say about it. [Edited by - Bozebo on April 25, 2010 8:30:04 PM]
Advertisement
if(x <= (*visCellsI)->right && x >= (*visCellsI)->left && z <= (*visCellsI)->top && z >= (*visCellsI)->bottom)


(You have to dereference the iterator and the pointer)
Quote:Original post by pablo24
if(x <= (*visCellsI)->right && x >= (*visCellsI)->left && z <= (*visCellsI)->top && z >= (*visCellsI)->bottom)


(You have to dereference the iterator and the pointer)


Oh wow thanks. That solved a bunch of problems.

Would it be faster to dereference once and store it in the function or dereference 4 times as you examplified?

[Edited by - Bozebo on April 25, 2010 7:38:00 PM]
Quote:Original post by Bozebo
Would it be faster to dereference once and store it in the function or dereference 4 times as you examplified?


Conceptually, probably.

In terms of code, no. The compiler will make the transformation assuming that it helps.

However, the resulting code is probably cleaner. Try writing it both ways and see what looks better to you.

This topic is closed to new replies.

Advertisement