Hello,
I'm creating a text based RPG game in C++. I'm trying to move the player creation code in main to a function below it. I've created a pointer to a character object and calling a function to return the reference of the newly created character. Is there a problem with doing it this way?
I ask because I'm having issues elsewhere in code relating to the persistence of the player's inventory. I add items to the inventory vector using a function for example, but they don't stay added.
Also, I've tried not using a function and passing references around to create the player character and everything works just fine, so that's what makes me suspicious of the code below....
Thanks!
Player* createNewChar();
int main(){
...
Player* pPlayer = 0;
...
}
...
Player* createNewChar(){
string pName = selectName();
cout << "Welcome, " << pName << ".\n";
string pClass = selectClass();
cout << "Creating your new character...!";
Player player(pName, pClass);
return &player;
}
...