Problems creating an Object!

I'm having a problem trying to declare my object of my Player class..

Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "Game.h"
using namespace std;

void Instructions();
int main()
{
	Instructions();

	Game game;
	game.Run();
	
	return 0;
}
void Instructions()
{
	cout << "Please type /help for help!" << endl;
}

Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Game.h"
#include "Player.h"

Player matt;
matt// trying to declare player!!!


Game::Game()
{

}
Game::~Game(){}

void Game::Run()
{
	//Game Loop, Always getting user commands to call Functions
	string userInput;
	bool gameRunning = true;
	while (gameRunning != false)
	{   //Getting User Commands
		cin >> userInput;
		ClearScreen();
		//Calling Command Functions
		Command(userInput, gameRunning);
		
	}
};

	
}

Player.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef __PLAYER_H_INCLUDED__
#define __PLAYER_H_INCLUDED__
#include <string>
using namespace std;

class Player
{
	Player();
	Player(string, int, int, int, int, int);
	~Player();
	string Name;
	int Health;
	int Mana;
	int Exp;
	int ExpCap;
	int Level;

public:

	int getHealth();
	int getMana();
	int getExp();
	int getLevel();

	void setHealth(int hp);
	void setMana(int mp);
	void setExp(int xp);
	void setLevel(int lvl);

};
#endif __PLAYER_H_INCLUDED__ 

Player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "Player.h"

Player::Player()
{

}
Player::Player(string NAME, int HP, int MP, int XP, int XPCAP, int LVL)
{
	Name = NAME;
	Health = HP;
	Mana = MP;
	Exp = XP;
	ExpCap = XPCAP;
	Level = LVL;
}

Player::~Player()
{

}


I cut a lot of the code out because it created the post way to long. I've tried a lot of different thing to try and make it work so it may look more wrong now than it did :(
Last edited on
I'm having a problem trying to declare my object of my Player class..
What exactly do you have a problem with?
ugh... game.h???

closed account (SECMoG1T)
am not sure but i think your player default constructor is a private member of your class player, try make it public though i have never used private constructors ,so i might not be sure if they work.
Last edited on
Alright I fixed the Problem.. I was creating a private default constructor and also trying to create a object in a Global Scope(I should have been trying this in a function) like my Game::Run()

Thanks Guys!
closed account (SECMoG1T)
i guess you can created an object anywhere you want provided it's class is completly defined and the are proper includes.
Topic archived. No new replies allowed.