![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
Including your home-made header files
I made "player.h" for "player.cpp" ... But how do you include the "player.h" ?
I tried with <player.h> says it can't find the file... If I do "player.h" I get freaky errors... Here's the code from player.cpp: Note that the program is far from done, I just tried compiling this file and I got the errors which is mentioned at the bottom. #include <iostream>
#include "player.h"
#include <time.h>
using namespace std;
player::player()
{
this->strength = 0;
this->agility = 0;
this->intelligence = 0;
this->gold = 0;
this->exp = 0;
this->health = 0;
this->mana = 0;
this->max_health = 0;
this->max_mana = 0;
}
player::~player()
{
}
void set_strength (unsigned int strength)
{
this->strength = strength;
}
void set_agility (unsigned int agility)
{
this->agility = agility;
}
void set_intelligence (unsigned int intelligence)
{
this->intelligence = intelligence;
}
unsigned int get_strength ()
{
return this->strength;
}
unsigned int get_agility ()
{
return this->agility;
}
unsigned int get_intelligence ()
{
return this->intelligence;
}
void set_stats (int base, int max_rnd, int points)
{
srand(time(NULL));
int c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->strength = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->agility = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->intelligence = base + c;
points = points - c;
}
void text_dump ()
{
for ( ; ; ){
set_stats(15, 10, 15);
cout << "str = " << this->strength << endl;
cout << "agi = " << this->agility << endl;
cout << "int = " << this->intelligence << endl;
cout << "health = " << this->strength * 5 << endl;
cout << "mana = " << this->intelligence * 3 << endl;
cout << "gold = " << this->gold << endl;
cout << "exp = " << this->experience << endl;
}
}d:\program\microsoft visual studio\vc98\include\time.h(37) : error C2143: syntax error : missing ';' before 'string' d:\program\microsoft visual studio\vc98\include\time.h(37) : fatal error C1004: unexpected end of file found Error executing cl.exe. Here comes the player.h file: #ifndef __PLAYER_H__
#define __PLAYER_H__
class player {
public:
player();
~player();
void set_strength (unsigned int strength);
void set_agility (unsigned int agility);
void set_intelligence (unsigned int intelligence);
unsigned int get_strength ();
unsigned int get_agility ();
unsigned int get_intelligence ();
void set_stats (int base, int max_rnd, int points);
void text_dump();
private:
unsigned int strength;
unsigned int agility;
unsigned int intelligence;
int health;
int mana;
int max_health;
int max_mana;
unsigned int gold;
unsigned int exp;
}
#endif |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
Just noticed I had some "player::" errors, cba to fix them here, did it in my own code, still the same errors.
Oh and Im using MSVC++ 6.0 (Professional Edition, doubt it matters ) |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Try putting #include <time.h> before your own header file. I don't think it matters, but it's worth a shot.
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
Here your code fixed... i added comments to the changes i made. ( i think your main problem was the ; that was missing before the class closing.
player.h: #ifndef __PLAYER_H__
#define __PLAYER_H__
class player {
//switched private with public... ( nothing wrong just i like it better that way)
private:
unsigned int strength;
unsigned int agility;
unsigned int intelligence;
int health;
int mana;
int max_health;
int max_mana;
unsigned int gold;
unsigned int exp;
public:
player();
~player();
void set_strength (unsigned int strength);
void set_agility (unsigned int agility);
void set_intelligence (unsigned int intelligence);
unsigned int get_strength ();
unsigned int get_agility ();
unsigned int get_intelligence ();
void set_stats (int base, int max_rnd, int points);
void text_dump();
//added this ; that i think was your problem
};
#endifplayer.cpp: #include<iostream>
//changed time.h to ctime...
#include<ctime>
using namespace std;
//moved the include outside the namespace std
#include "player.h"
player::player()
{
this->strength = 0;
this->agility = 0;
this->intelligence = 0;
this->gold = 0;
this->exp = 0;
this->health = 0;
this->mana = 0;
this->max_health = 0;
this->max_mana = 0;
}
player::~player()
{
}
//added the player:: to all the functions
void player::set_strength (unsigned int strength)
{
this->strength = strength;
}
void player::set_agility (unsigned int agility)
{
this->agility = agility;
}
void player::set_intelligence (unsigned int intelligence)
{
this->intelligence = intelligence;
}
unsigned int player::get_strength ()
{
return this->strength;
}
unsigned int player::get_agility ()
{
return this->agility;
}
unsigned int player::get_intelligence ()
{
return this->intelligence;
}
void player::set_stats (int base, int max_rnd, int points)
{
srand(time(NULL));
int c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->strength = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->agility = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->intelligence = base + c;
points = points - c;
}
void player::text_dump ()
{
for ( ; ; ){
set_stats(15, 10, 15);
cout << "str = " << this->strength << endl;
cout << "agi = " << this->agility << endl;
cout << "int = " << this->intelligence << endl;
cout << "health = " << this->strength * 5 << endl;
cout << "mana = " << this->intelligence * 3 << endl;
cout << "gold = " << this->gold << endl;
//change it to exp (you wrote experience)
cout << "exp = " << this->exp << endl;
}
}-codetaino
__________________
"God bless u all" :) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|