   Weapons intialization
  I have just finished defining and prototyping my weapons for my game.  When I got to test it in a generic main file, it won't compile.  Most of it is declared void and that causes some problems for some reason.  Also, it says some of my class types name no type.class GWeapon{    protected:  unsigned int m_ammo;....class Rifle : public GWeapon{   public:...static Rifle fireRate;void Rifle wDamage;};...I am wondering why it is doing this...can anyone help me?   
  void is a datatype and so is Rifle, so void Rifle is illegal.you should either have, Rifle xyz, or void xyz, (though i don't see how firerate can be either of the two, int or float seems more natural)   ;  Thanks Anon.  I got it to work last night and now I'm working on the .cpp file.  I was wondering if anyone could show me how I would implement the functions?  I think I need to do Pistol::particlePistol( functions) and then go into what it should do, initialize the damage and whatnot.  Any have any links or thoughts about how I am supposed to do that?   ;  what do you mean by implement the functions? <ClassName>::<FunctionName>(<Argument1>, <Argument2>, ... ){}do you mean that stuff or are you not shure what variables you need for your weapon?   ;  That stuff. :)  I know most of the variables I'm going to need.  I wasn't sure on how I would go about doing it.  When I try to compile it in a dummy program, to make sure it's all declared and set up right, I get errors.  I'll edit this once I get the errors and you can see what I mean.  DO you know of any sites or articles I could read that would help me do this?  I have to add my player.h/.cpp class in the header once I get it done and I also need the player to be able to shoot the weapons.  I know the variables and methods I want to use to get that situated but I just need to see how I am supposed to go about it.  How would I make sure no errors are in there?EDIT:  Here is the full .h code for the weapons.  I know there are some errors here.  Could you tell me a better way to do it?// class declaration of GWeapon#ifndef GWEAPON_H#define GWEAPON_H#include "Log.cpp"class GWeapon{ protected: unsigned int m_ammo; // Ammo for how much is left in weapons public:   virtual void Fire(int); // Fires weapon depending on what is calling it   int laserLength; // Laser length so that weapons can be reloaded   static int wModify; // Modify function for adding periphs   virtual void wUpdate(int); // Updates weapon once modification is complete and for ammo   virtual void wDamage(int); // Damage that various weapons do   virtual void laserShellDiscard(int); // for visual effects.  May be moved elsewhere   int Reload() // Reload function for various weapons{ m_ammo = 100;};   int getShellLength; //Gets correct laser shell length so weapon ammo can update correctly};class Pistol : public GWeapon{ public:   int pShellLength;  // Length of Pistol shells for reloading   static int pLaserPower(); // Pistol function for how strong it is   static int Charge(); // Charges Pistol if shoot button is held for x amt of time   Pistol Fire(); // Fires Pistol   Pistol wDamage();   Pistol Reload(); // Reloads pistol  };Pistol::particlePistol(int pShellLength, int pLaserPower, int Charge, Pistol Fire, Pistol wDamage, Pistol Reload);    virtual ~particlePistol();    int pShellLength = 1;    int pLaserPower = 3;    int Charge = pLaserPower + 3;    Pistol Reload;class Rifle : public GWeapon{ public:   int rShellLength;   Rifle Fire();   Rifle wDamage();   static Rifle fireRate; // Firerate for any rifle.  Updates accordingly   Rifle Reload();};class Shotgun : GWeapon{ public:   int sShellLength;   static int sPumpRate; //As gunfights get more intense, adrenaline increases pump speed   Shotgun Reload();   Shotgun Fire();   Shotgun wDamage();};class Grenade : GWeapon{ public:   int Fire;   float Radius; // Radius for all grenades.  Changes accordingly   float Timer; // Timer. Changes accordingly   Grenade wDamage();   float Delay;   Grenade Reload();};class wObject : GWeapon{ public:   int Strike;   int wBreak;   wObject wDamage();   wObject wStrength();};#endif [Edited by - kidd175 on May 28, 2006 6:51:50 PM];  why do you try to instance an object of the same class within that class declaration? i don't get it.class xyz{public:xyz MyFunction();...};doesn't make ANY sense. are you trying to create a constructor / destructor there? in that case you just need to type xyz(); for the constructor and ~xyz() for the destructor.to declare a function within a class, you just need to do the same as if the function were out the class:int myfunc();class blub{int myfunc() { some code }bool secondfunc();};you need to do this:bool blub::secondfunc(){}if you've just declared the function header in the class and the code is somewhere else ( most likely in the cpp file )perhaps you should consider buying a book about c++ and especially classes: they're not so hard, after you're in them. it takes some time, but this is basic stuff and in my point of view c++ makes much more fun with 'em. :)i've searched on the net, google will spit out several tutorials about classes:http://www.cplusplus.com/doc/tutorial/classes.htmlthis is just the first result for: 'c++ classes tutorial'you should put effort in this section of c++, i love to play around with classes ^^   ;  uh-oh#include "Log.cpp"Are you sure about that dude ? ;) Unless you excluded Log.cpp from the build (talking in VC++ words) you may get serious complaints form you compiler. Didn't you mean to include Log.h instead ?Wish you good luckJanta   ;Quote:Original post by kidd175That stuff. :)  I know most of the variables I'm going to need.  I wasn't sure on how I would go about doing it.  When I try to compile it in a dummy program, to make sure it's all declared and set up right, I get errors.  I'll edit this once I get the errors and you can see what I mean.  DO you know of any sites or articles I could read that would help me do this?  I have to add my player.h/.cpp class in the header once I get it done and I also need the player to be able to shoot the weapons.  I know the variables and methods I want to use to get that situated but I just need to see how I am supposed to go about it.  How would I make sure no errors are in there?EDIT:  Here is the full .h code for the weapons.  I know there are some errors here.  Could you tell me a better way to do it?*** Source Snippet Removed ***well since you got this:class GWeapon{ protected: unsigned int m_ammo; // Ammo for how much is left in weapons public:   virtual void Fire(int); // Fires weapon depending on what is calling it   int laserLength; // Laser length so that weapons can be reloaded   static int wModify; // Modify function for adding periphs   virtual void wUpdate(int); // Updates weapon once modification is complete and for ammo   virtual void wDamage(int); // Damage that various weapons do   virtual void laserShellDiscard(int); // for visual effects.  May be moved elsewhere   int Reload() // Reload function for various weapons{ m_ammo = 100;};   int getShellLength; //Gets correct laser shell length so weapon ammo can update correctly};the pistol class declaration should look something like this:class Pistol : public GWeapon{ public:   int pShellLength;  // Length of Pistol shells for reloading   static int pLaserPower(); // Pistol function for how strong it is   static int Charge(); // Charges Pistol if shoot button is held for x amt of time   void Fire(); // Fires Pistol .. this and wDamage should match the virtual methods in GWeapon   void wDamage();   void Reload(); // Reloads pistol //if all weapons use identical reload functions you won't need this one, if not you should declare it as virtual in the GWeapon class.  };;  Thanks everyone.  I've gone back and edited my code to include the help and fixes you've all gave me.Janta - I did mean .h so that is also fixed.  After reading that I tried to instance inside the class which should be handled in the .cpp file, I feel amazingly, enormously idiotic.  Sorry folks.  I'm getting back into programming and I figured I would jump right in and learn from my mistakes.  You've all made this reimmersion so much more easier.Brandon/Kidd175   ;// class declaration of GWeapon#ifndef GWEAPON_H#define GWEAPON_H#include "Log.h"class GWeapon{    protected:  unsigned int m_ammo; // Ammo for how much is left in weapons    public:  virtual void Fire(); // Fires weapon depending on what is calling it  int laserLength; // Laser length so that weapons can be reloaded and ammo added  static int wModify; // Modify function for adding periphs  virtual void wUpdate(); // Updates weapon once modification is complete and for ammo  virtual void wDamage(); // Damage that various weapons do  virtual void laserShellDiscard(); // for visual effects.  May be moved elsewhere  int Reload; // Reload function for various weapons  float getShellLength; //Gets correct laser shell length so weapon ammo can update correctly};class Pistol : public GWeapon{ public:   float pShellLength;  // Length of Pistol shells for reloading and picking up ammo   static int pLaserPower(); // Pistol function for how strong it is   static int Charge(); // Charges Pistol if shoot button is held for x amt of time   void Fire(); // Fires Pistol   void wDamage(int);   int Reload(); // Reloads pistol   virtual void particlePistol(float pShellLength, int pLaserPower, int Charge, int Fire, int wDamage, int Reload);   virtual void sonicPistol(float pShellLength, int pLaserPower, int Charge,int Fire,int wDamage, int Reload);   virtual void bePistol(float pShellLength, int pLaserPower, int Charge,int Fire,int wDamage, int Reload);   virtual void pulsePistol(float pShellLength, int pLaserPower, int Charge,int Fire,int wDamage, int Reload);   Pistol();   virtual ~Pistol();};class Rifle : public GWeapon{ public:   float rShellLength;   void Fire();   void wDamage();   static int fireRate; // Firerate for any rifle.  Updates accordingly   int Reload();};class Shotgun : GWeapon{ public:   int sShellLength;   static int sPumpRate; //As gunfights get more intense, adrenaline increases pump speed   int Reload();   void Fire();   void wDamage();};class Grenade : GWeapon{ public:   void Fire();   float Radius; // Radius for all grenades.  Changes accordingly   float Timer; // Timer. Changes accordingly   void wDamage();   float Delay;   int Reload();};class wObject : GWeapon{ public:   int Strike;   int wBreak;   void wDamage();   static int wStrength();};#endif.cpp:  This is just messing around, getting things in there and trying to compile the code.  Nothing is working and when you try to compile the two, you'll see the errors I get...their confusing me//GWeapon.cpp#include "gweapon.h"class Pistol : class GWeapon;Pistol::particlePistol(float pShellLength, int pLaserPower, int Charge, int Fire, int wDamage, int Reload){    float particleShellLength = 1;    int particleLaserPower = 3;    int Charge = particleLaserPower + 3;    int wDamage = particleLaserPower;    int Reload;}Pistol::~particlePistol(){};Pistol::pulsePistol(float pShellLength, int pLaserPower, int Charge, int Fire, Pistol wDamage, Pistol Reload){    float pShellLength = 1.3;    int pLaserPower = 4;    int Charge = pLaserPower + 3;    Pistol wDamage = pLaserPower;    Pistol Reload;}Pistol::~pulsePistol(){};Pistol::bePistol(float pShellLength, int pLaserPower, int Charge, int Fire, Pistol wDamage, Pistol Reload){    float pShellLength = 1;    int pLaserPower = 3;    int Charge = pLaserPower + 3;    Pistol wDamage = pLaserPower;    Pistol Reload;}Pistol::~bePistol(){};Pistol::sonicPistol(float pShellLength, int pLaserPower, int Charge, int Fire, Pistol wDamage, Pistol Reload){    float pShellLength = 1.5;    int pLaserPower = 3;    int Charge = pLaserPower + 3;    Pistol wDamage = pLaserPower;    Pistol Reload;}Pistol::~sonicPistol(){};I appreciate the help and anything else you all are able to provide me.  I am just messing around with the .cpp file but when I try to compile and correct the errors it gives me, they don't seem to go away or anything...I think I'm just messing something up.....Brandon/KiddEDIT:  Also, I wanted to know if you knew any good algorithm sites I could look at and learn from.  I want to try my fire and reload functions but I can't seem to get around the firing and reloading the ammo and all that.   