   Passing an object as a parameter
  I recently upgraded to Visual Studio .Net 2005 from 2003 edition.  I am having trouble passing an object as a parameter.  Here is the way I did it before.#ifndef _ENEMIES_H#define _ENEMIES_H#include "PlayerControl.h"#include "game.h"#include "global.h"class enemies{public:enemies(int);  //Constructor// 1 = Fire Dragon// 2 = Orc// 3 = Grey Troll// 4 = Dino Attacking~enemies(); //Destructorvoid update(PlayerControl *player, int direction);  //update enemies including AII am getting a syntax error: : error C2061: syntax error : identifier 'PlayerControl'Does anyone know why this doesn't work anymore, I always did it this way before.   
  This error is only in relation to how the type is defined. In other words PlayerControl is either not defined or is defined in correctly. Check the contents of the header file.Dave   ;  Thanks for posting, I don't see an error but maybe you would spot one for me.#ifndef _PLAYERCONTROL_H#define _PLAYERCONTROL_H#include "game.h"#include "global.h"class PlayerControl{public://ConstructorPlayerControl();//Destructor~PlayerControl();//Function to move playervoid Walk(int);//Function to make player attackvoid Attack(int);//Draw playervoid Draw();//get x locationint getX();//get y locationint getY();//get player directionint getDirection();private:bool attacking;LPDIRECT3DTEXTURE9 blue_knight_walk_image;LPDIRECT3DTEXTURE9 blue_knight_attack_image;D3DXVECTOR3 position;int stopFrame, startFrame, currDirection, attackDirection;bool attack;   //main bool variable set false when player is done attackingbool startAttack;   //Variable to start attackbool justAttacked;  //Variable set to determine if player just attackedSPRITE blueknight;int blueknightRow; //Variable to track players current positionint blueknightCol; //Variable to track players current position};#endif;  Do either game.h or global.h include either of the two headers that you pasted?If so, you might be suffering from a case of circular inclusion.Dave   ;  Adam,Its best not to create dependencies between headers (#include'ing headers within headers).  Doing so can create "header chains" or "header loops" which increase your compile time, increase the likelyhood of name collisions, and increases the likelyhood of multiply defined types.Its better to put the necessary header files needed in your "source" files, and just use forward declerations in your header files.  I notice in the example you posted that you're not actually using PlayerControl in this header file, you're just declaring it as a parameter for Update(), so forward declerations would work perfectly in this case.Just add 'class PlayerControl;' above the enemies class decleration, and then remove the include for "PlayerControl.". Vwalla!  No more dependency, and potentially faster compile times.  Getting the most efficient use of header files isnt an easy topic, so if you really want to get that working, just let me know and I'd be happy to explain, or post a question about it.Cheers!   ;Quote:Original post by DaveDo either game.h or global.h include either of the two headers that you pasted?If so, you might be suffering from a case of circular inclusion.DaveThanks, I removed all of the duplicate includes, and I still get the same error.  I never received that error for trying to pass an object, I wonder if there is something new with 2005 that I don't know about.   ;Quote:Original post by jwalshAdam,Its best not to create dependencies between headers (#include'ing headers within headers).  Doing so can create "header chains" or "header loops" which increase your compile time, increase the likelyhood of name collisions, and increases the likelyhood of multiply defined types.Its better to put the necessary header files needed in your "source" files, and just use forward declerations in your header files.  I notice in the example you posted that you're not actually using PlayerControl in this header file, you're just declaring it as a parameter for Update(), so forward declerations would work perfectly in this case.Just add 'class PlayerControl;' above the enemies class decleration, and then remove the include for "PlayerControl.". Vwalla!  No more dependency, and potentially faster compile times.  Getting the most efficient use of header files isnt an easy topic, so if you really want to get that working, just let me know and I'd be happy to explain, or post a question about it.Cheers!Thank you for the help, that must be my problem.  By adding class PlayerControl, if you don't mind could you give me a quick example of how I would do that.  Would it be like this:#include "game.h"class PlayerControl;class enemies{public:enemies(int);  //Constructor// 1 = Fire Dragon// 2 = Orc// 3 = Grey Troll// 4 = Dino Attacking~enemies(); //Destructorvoid update(PlayerControl *player, int direction);  //update enemies including AIvoid Draw();  //draw enemyint Collision(SPRITE sprite1, int X, int Y, int size); //detects collisionThanks again for the help, I really appreciate everyone taking the time to help me out.;  Adam,Yes, exactly like that.Any time you need to declare a class, structure, enum, etc...but aren't going to actually use the class within the file, its perfectly acceptable (and desirable) to just declare the class so that your current file knows about it.Using the class means declaring a member variable which is not a reference or pointer.  Using the class also means accessing the function or member variables of the class.  So just declaring pointers to the class within your header file is the time to use forward declerations.  Just observation, this means you should not put implementation in your header files, but instead always keep your implementation in source files when possible.Examples:// ClassB.hclass ClassA;class ClassB{public:    // Since this is just a pointer, the compiler doesnt need to know the    // Specifics of ClassA, it'll resolve those at run-time.    void DoSomething( ClassA* pClassA );}// ClassB.h#include "ClassA.h"class ClassB{public:    // Here I USE the class in the header, so the compiler must know the full    // definition of the class to determine if the method I'm calling is valid,    // with the correct paramaters, etc...thus...I HAVE to include it's// header file.  Forward decleration will NOT work.    void DoSomething( ClassA* pClassA )    {   pClassA->MyMemberFunc();    }}// ClassB.h#include "ClassA.h"class ClassB{public:    void DoSomething( ClassA* pClassA );private:    // This is NOT a pointer, so the compiler needs to know the size of ClassA    // in order to assure correct object size, etc...so once again, I MUST    // include the header file for ClassA.  Forward declerations wont work.    ClassA m_MyClassAObject;}Cheers!   ;Quote:Original post by jwalshAdam,Yes, exactly like that.Any time you need to declare a class, structure, enum, etc...but aren't going to actually use the class within the file, its perfectly acceptable (and desirable) to just declare the class so that your current file knows about it.Using the class means declaring a member variable which is not a reference or pointer.  Using the class also means accessing the function or member variables of the class.  So just declaring pointers to the class within your header file is the time to use forward declerations.  Just observation, this means you should not put implementation in your header files, but instead always keep your implementation in source files when possible.Examples:*** Source Snippet Removed ****** Source Snippet Removed ****** Source Snippet Removed ***Cheers!Thank you so much for the help, after moving things around and improving my code a little it worked perfectly.  The only issue I had is needing the DirectX header files in each class so I left them in game.h so they could be included.  Thanks again for all the help.  I agree that putting implementation in separate source files is a lot better except of course when creating a class template.   ;  No problem, post questions any time. [smile]   