Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 5th, 2005, 6:26 PM   #1
Siphon
Newbie
 
Join Date: Feb 2005
Posts: 25
Rep Power: 0 Siphon is on a distinguished road
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
Siphon is offline   Reply With Quote
Old Feb 5th, 2005, 6:28 PM   #2
Siphon
Newbie
 
Join Date: Feb 2005
Posts: 25
Rep Power: 0 Siphon is on a distinguished road
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 )
Siphon is offline   Reply With Quote
Old Feb 5th, 2005, 6:42 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Try putting #include <time.h> before your own header file. I don't think it matters, but it's worth a shot.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 5th, 2005, 9:26 PM   #4
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
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
};

#endif

player.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" :)
codetaino is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC