Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with my first CPP program - header and source
    primarykey
    data
    text
    <p>Im spending my saturday night not dressed up for halloween but rather sitting trying to learn CPP :D</p> <p>anyways could someone please help me, Below I have included my source code, basically when I try compiling this form the terminal I'm getting a lot of errors, basically stating that the variables "name, ho, etc" are not declared, yet I have included my header file, so could someone pleas shave a look at this and maybe tell me what is missing? Thank you so much in advance guys!</p> <pre><code>#ifndef __TPLAYER__ #define __TPLAYER__ //prevent multiple #includes TPlayer { private: char name; int hp; int dmg; int wep; public: TPlayer(void); ~TPlayer(void); //Naming void SetName(char *_name); char GetName(void); //Health void SetHealth(int *_hp); int GetHealth(void); //Damage int SetDamage(int *_dmp) //Weapon void SetWeapon(int *_wep); int GetWeapon(void); }; #endif /* TPlayer.h */ </code></pre> <p>and here is my source file:</p> <pre><code>#include "TPlayer.h" ///////////////// // Constructor ///////////////// TPlayer::TPlayer(void) { name = ""; hp = 0; dmg = 0; wep = 0; } /////////////////// // Destructor /////////////////// ~TPlayer::TPlayer() { delete name; delete hp; delete dmg; delete wep; } /////////////////// // Naming /////////////////// void SetName(char *_name) { name = _name; } char GetName(void) { return *name; } </code></pre> <p>And so forth, yet its telling me that for example, name etc has not been as shown below:</p> <pre><code>TPlayer.h:4: error: function definition does not declare parameters TPlayer.cpp:6: error: ‘TPlayer’ has not been declared TPlayer.cpp:6: error: ISO C++ forbids declaration of ‘TPlayer’ with no type TPlayer.cpp: In function ‘int TPlayer()’: TPlayer.cpp:8: error: ‘name’ was not declared in this scope TPlayer.cpp:9: error: ‘hp’ was not declared in this scope TPlayer.cpp:10: error: ‘dmg’ was not declared in this scope TPlayer.cpp:11: error: ‘wep’ was not declared in this scope TPlayer.cpp: At global scope: TPlayer.cpp:16: error: expected class-name before ‘::’ token TPlayer.cpp: In function ‘void SetName(char*)’: TPlayer.cpp:30: error: ‘name’ was not declared in this scope TPlayer.cpp: In function ‘char GetName()’: </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload