   undeclared identifier?
  I've got two nasty errors in my game, they are in map.cpp file in getEnemy implementation, but then I put implementatio in .h file compiler does not show errors, what is problems?Here's errors:rpg\map.cpp(47) : error C2065: 'enemies' : undeclared identifierrpg\map.cpp(47) : error C2228: left of '.enemy' must have class/struct/unionmap.cpp#include "map.h"Map::Map(int width, int height){mWidth = width;mHeight = height;mapCoords = new int*[mHeight];for (int i = 0;i< mWidth;i++){mapCoords = new int [mWidth];}    //array for enemy locationsenemies = new Entity*[mHeight];for (int i = 0;i< mWidth;i++){enemies = new Entity [mWidth];}}void Map::SetWidth(int width){mWidth = width;}void Map::SetHeight(int height){mHeight = height;}int Map::GetWidth(){return mWidth;}int Map::GetHeight(){return mHeight;}int Map::GetMapCoord(int x,int y){return mapCoords[x][y];}void Map::SetMapCoord(int x, int y,int value){mapCoords[x][y] = value;}Enemy getEnemy(int x,int y){return *enemies[x][y].enemy;}map.h#ifndef MAP_H#define MAP_H#include "engine.h"#include "entity.h"class Entity;class Map{public:Map(int width = 12,int height = 12);//accesor methodsvoid SetWidth(int width);void SetHeight(int height);int GetWidth();int GetHeight();int GetMapCoord(int x,int y);void SetMapCoord(int x,int y,int value);Enemy getEnemy(int x,int y);private:int mWidth;int mHeight;int ** mapCoords;Entity ** enemies;};#endif
  I forgot to write Map:: behing getEnemy... sorry :(   ;  i corrected method implemenatation, but when I run game i got runtime error in same method:Unhandled exception at 0x00411aed in RPG.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.   ;  You create an array of int pointers (mapCoords = new int*[mHeight]) but loop through them indexing using mWidth. What if width and height are not the same ?Also you are trying to access mapCoords[ x ][ y ] which is wrong.Did you mean mappCoords = new int*[ mWidth * mHeight ]; ???   ;Quote:Original post by GregMichaelYou create an array of int pointers (mapCoords = new int*[mHeight]) but loop through them indexing using mWidth. What if width and height are not the same ?Also you are trying to access mapCoords[ x ][ y ] which is wrong.Did you mean mappCoords = new int*[ mWidth * mHeight ]; ???I see you dont understood me clearly... it is all right with mapCoords, please look at Entity** enemies :)   ;  I dis it with mapCoorsd differently, i posted bad implementation of this loop , in my code it seems allright...   ;Quote:Original post by kaktusas2598I see you dont understood me clearly...He probably understands you just fine.The fact remains, he's pointing out something that will be yet another nasty error in the future if you ever have mWidth != mHeight, which seems like a given since you made them separate variables.And by 'nasty error' I mean 'subtle hard-to-debug runtime errors' rather than the simple compiler errors you started this post with.mapCoords = new int*[mHeight];for (int i = 0;i< mWidth;i++)enemies = new Entity*[mHeight];for (int i = 0;i< mWidth;i++)Your SetWidth/SetHeight are at best buggy at the moment as well.  While they'll change the variable, they won't change the size of the mapCoords or enemies array.  This is another nasty error in the making.  I would remove the function outright for now.EDIT:  From this we can see that you're using some uninitialized memory when you have an access violation at 0xcdcdcdcd.  Chances are either mWidth != mHeight, or you forgot to assign a pointer to Map to a valid instance (e.g. newed) -- we would have to see the calling code of whatever is crashing to know for certain.   ;Quote:Original post by MaulingMonkeyYour SetWidth/SetHeight are at best buggy at the moment as well.  While they'll change the variable, they won't change the size of the mapCoords or enemies array.  This is another nasty error in the making.  I would remove the function outright for now.I dont need that at all, i think I will delete these methods;Quote:Original post by MaulingMonkeyEDIT:  From this we can see that you're using some uninitialized memory when you have an access violation at 0xcdcdcdcd.  Chances are either mWidth != mHeight, or you forgot to assign a pointer to Map to a valid instance (e.g. newed) -- we would have to see the calling code of whatever is crashing to know for certain.I dont understood that text very well, but can you recommend me how to get rid of that error?