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"
Code: Select all
#include <iostream>
#include "Game.h"
int main()
{
Character Player;
CharacterCreation();
Player.Print();
}
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();
};
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();
}