   Issues with prototyping a class
  I have issues when trying to prototype my classes Agent, Bullet and Map. I recieve the following errors:f:\Source\teamai\DataMap.cpp(238): error C2027: use of undefined type 'Agent'f:\Source\teamai\DataMap.cpp(208): error C2027: use of undefined type 'Bullet'f:\Source\teamai\DataMap.cpp(210): error C2027: use of undefined type 'Map'f:\Source\teamai\DataMap.cpp(238): error C2227: left of '->addDamage' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(213): error C2227: left of '->getHeading' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(224): error C2227: left of '->getLastX' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(225): error C2227: left of '->getLastY' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(226): error C2227: left of '->getLastZ' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(244): error C2227: left of '->getX' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(208): error C2227: left of '->getY' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(223): error C2227: left of '->getZ' must point to class/struct/unionf:\Source\teamai\DataMap.cpp(210): error C2228: left of '.GetAgent' must have class/struct/union type   //DataMap.h#include "TileMap.h"#include "common.h"#include <windows.h>#include "exception.h"#include <math.h>extern class Agent;extern class Bullet;extern class Map;extern class Tile;extern Map g_CMap;class DataMap  {public:DataMap();virtual ~DataMap();bool testCollision(int iX, int iY);int getAgent(int iX, int iY);void bulletHit(Bullet *CBullet);private:int m_iAgentMap[256][256];TileMap *m_CTileMap;};//DataMap.cpp#include "DataMap.h"void DataMap::bulletHit(Bullet *CBullet){Agent *CAgent;TPoint tPoint1,tPoint2,tPoint3,tPoint4;TIntersect tIntersect;float fDistance;Tile *CTile;//check if agent is at positionif (m_iAgentMap[CBullet->getX()][CBullet->getY()]>-1){CAgent = g_CMap.GetAgent(m_iAgentMap[CBullet->getX()][CBullet->getY()]);//find agents planetPoint1.fX = CAgent->getX() + (sin((CAgent->getHeading()+90) * PIr) * -0.5);tPoint1.fY = CAgent->getY() - (cos((CAgent->getHeading()+90) * PIr) * -0.5);tPoint1.fZ = 0.0f;tPoint2.fX = CAgent->getX() + (sin((CAgent->getHeading()+90) * PIr) * 0.5);tPoint2.fY = CAgent->getY() - (cos((CAgent->getHeading()+90) * PIr) * 0.5);tPoint2.fZ = 1.0f;//find bullets planetPoint3.fX = CBullet->getX();tPoint3.fY = CBullet->getY();tPoint3.fZ = CBullet->getZ();tPoint4.fX = CBullet->getLastX();tPoint4.fY = CBullet->getLastY();tPoint4.fZ = CBullet->getLastZ();tIntersect = findIntersect(&tPoint1,&tPoint2,&tPoint3,&tPoint4,true);//check if line intersected segment on xy planeif (tIntersect.bIntersectSegmentXY){float fDistance = (float)(abs(tIntersect.tIntersectPoint.fX - tPoint1.fX) + abs(tIntersect.tIntersectPoint.fY - tPoint1.fY));//check if line intersected segment on z planeif (tIntersect.bIntersectSegmentZ){CAgent->addDamage(fDistance,tIntersect.tIntersectPoint.fZ);}}}//check if static object at that positionCTile = m_CTileMap->GetTile(CBullet->getX(),CBullet->getY());if (CTile->getStaticObjectTypeID() > 0){//object exists at positionCTile->getStaticObject()->addHit(1);}}What am I doing wrong to cause these errors?Also, is it better to declare extern in front of a class prototype? Or should I just drop it?EDIT: Added #include "DataMap.h" to datamap.cpp   ----MikePortfolio: Http://members.iinet.net.au/~slyonsTeam AI: Http://members.iinet.net.au/~slyons/teamai[edited by - Mike737 on February 3, 2004 9:54:42 PM]
  I''m assuming you''re #including DataMap.h in DataMap.cpp, and just didn''t show us?Also, you don''t need the externs for the forward declarations.  They''re just for linkage.   I like pie. ;quote:Original post by RenderTarget   I'm assuming you're #including DataMap.h in DataMap.cpp, and just didn't show us?Yes, I do have #include "DataMap.h" in Datamap.cpp   ----MikePortfolio: Http://members.iinet.net.au/~slyonsTeam AI: Http://members.iinet.net.au/~slyons/teamai [edited by - Mike737 on February 3, 2004 9:53:09 PM];  Im gonna take a stab at saying just using "extern class ****" isn''t enough for the compiler. It may want to see the actual prototype of the class before allowing you to use any of it''s member functions. ;  Where is the class Agent fully declared?If you don''t include that declaration, then you can only pass around pointers to Agent''s, but not access it''s members.  class Agent;void Test( Agent* pAgent ) //fine{ pAgent->addDamage();   //error (what is this addDamage you speak of?)}class Agent{ void addDamage();};void Test( Agent* pAgent ) //fine{ pAgent->addDamage();   //fine};  Also, if you have a member of the class''s type, you have to include the full declaration as well.  Just like when using member functions, you need more than just the forward declaration. ;quote:Original post by Thrump  Where is the class Agent fully declared?If you don''t include that declaration, then you can only pass around pointers to Agent''s, but not access it''s members. But soon as I add #include "Agent.h" into my DataMap.h file I recieve more errors. Some of these errors are:f:\Source\teamai\Agent.h(73): error C2061: syntax error : identifier ''DataMap''f:\Source\teamai\Agent.h(109): error C2501: ''Agent::DataMap'' : missing storage-class or type specifiersf:\Source\teamai\Agent.h(109): error C2501: ''Agent::m_CDataMap'' : missing storage-class or type specifiers  These errors never occured before I place the Agent.h include declaration in. //Agent.h#if !defined(AFX_AGENT_H__EDFB1F5F_EB93_4BBD_9785_358033384249__INCLUDED_)#define AFX_AGENT_H__EDFB1F5F_EB93_4BBD_9785_358033384249__INCLUDED_#include <windows.h>#include "LOS.h"#include "DataMap.h"#include "TileMap.h"#include "AStar.h"#include <time.h>#include "AgentCoverMap.h"#include "common.h"#include "weapon.h"#include "team.h"#include "exception.h"#include "inventory.h"class Team;class Agent{public:Agent(TileMap *CTileMap);virtual ~Agent();float getX();float getY();float getHeading();void update();void setDataMap(DataMap *CDataMap);void addDamage(float fXPosition, float fYPosition);private:LOS m_CLOS;DataMap *m_CDataMap;TileMap *m_CTileMap;};#endif // !defined(AFX_AGENT_H__EDFB1F5F_EB93_4BBD_9785_358033384249__INCLUDED_)So would it just be best to make a redefinition manually in Datamap.h of the methods when I prototype the classes? Would this method be accepted at a software house? Or should I drop the prototyping and somehow try to make agent.h be able to be included in datamap.h   ----MikePortfolio: Http://members.iinet.net.au/~slyonsTeam AI: Http://members.iinet.net.au/~slyons/teamai;quote:Original post by Mike737  So would it just be best to make a redefinition manually in Datamap.h of the methods when I prototype the classes? Hmm, I tried this and it resulted in Agent.h complaining of a redefinition of course.Can anyone help me with my original problem? ----MikePortfolio: Http://members.iinet.net.au/~slyonsTeam AI: Http://members.iinet.net.au/~slyons/teamai;  agent.h is using Datamap, and you haven''t told it that it exists yet. Try forward declaring it where you forward declare the team:class Team;class Datamap;class Agent{}; ;  There's an article on gamedev about header files that you may want to read. If you're understanding of them is a bit hazy, it's DEFINITELY worthwhile to learn about them. It took me a few years to understand them fully, but it's really quite simple.Check 'Articles and Resources'Edit:Here's the article:http://www.gamedev.net/reference/programming/features/orgfiles/There were a few questionable articles on header files, and I don't want to send you on a wild goose chase.   [edited by - Thrump on February 4, 2004 8:50:53 PM]