Variables Damn You!!

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Fenlig
Posts: 16
Joined: April 12th, 2013, 10:51 am

Variables Damn You!!

Post by Fenlig » May 14th, 2013, 10:25 pm

Hey Guys,

So I have my Character class and when I and define Character Player my CharacterCreation function cannot see it as its outside its code block.

Anyone able to offer a solution?

Kindest regards,
Simon

Game.h

Code: Select all

#pragma once

// Includes
#include "Characters.h"
Game.cpp

Code: Select all

#include <iostream>
#include "Game.h"

int main()
{
	Character Player;
	CharacterCreation();
	Player.Print();
}
Character.h

Code: Select all

#pragma once
#include <iostream>

// Functions
void CharacterCreation();

// Class
class Character
{
public:
	char m_strName[25];
	char m_strRace[25];
	int m_nUID;
	
	//Set Character Info
	void SetInfo( char *strName,char *strRace,int nUID );
	// Print Character Info
	void Print();
};
Character.cpp

Code: Select all

#include <iostream>
#include "Game.h"

void Character::SetInfo( char *strName,char *strRace,int nUID )
	{
		strncpy_s( m_strName,strName,25 );
		strncpy_s( m_strRace,strRace,25 );
		m_nUID = nUID;
	}

void Character::Print()
{
	using namespace std;
	cout << "Name: " << m_strName << endl << "Race: " << m_strRace << endl << "UID: " << m_nUID << endl;
}

void CharacterCreation()
{
	using namespace std;
	
	char strName[25];
	int strRace;
	
	cout << "What is your character name: ";
	cin >> strName;
	cout << "\n";
	cout << "What Race would you like to be?\n" << endl;
	cout << "1. Human - They are good at everything but masters of nothing race." << endl;
	cout << "2. Orc - They can take more damage but are alittle slow." << endl;
	cout << "3. Troll - Massive Basterds that have lots of hitpoints and deal the greatest damage, but are slow as shit" << endl;
	cout << "4. Goblin - Fast, weak and cowardly" << endl;
	cout << "5. Zombie - Take good amount of damage but are slow and weak" << endl;
	cin >> strRace;
	
	if( strRace == 1 )
	{
		Player.SetInfo( strName,"Human",1 );
	}
	if( strRace == 2 )
	{
		Player.SetInfo( strName,"Orc",1 );
	}
	if( strRace == 3 )
	{
		Player.SetInfo( strName,"Troll",1 );
	}
	if( strRace == 4 )
	{
		Player.SetInfo( strName,"Goblin",1 );
	}
	if( strRace == 5 )
	{
		Player.SetInfo( strName,"Zombie",1 );
	}

	Player.Print();
}

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Variables Damn You!!

Post by albinopapa » May 17th, 2013, 4:00 am

Couldn't you just put the function inside the character class
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply