Hello all ... could you please look over this code, critique it and let me know why it crashes at the end?
TIA!
main.cpp
Code:
#include <iostream>
#include <string>
#include "World.h"
#include "Player.h"
using namespace std;
int main(){
World world;
cout << "World Name = " << world.getName() << endl;
char* pName;
cout << "What is your name?" << endl;
cin >> pName;
Player player;
player.setName(pName);
cout << player.getName() << endl;
return 0;
}
player.h
Code:
#ifndef PLAYER_H
#define PLAYER_H
class Player {
public:
char* getName();
void setName(char* _pstrPlayerName);
protected:
char* _pstrPlayerName;
};
#endif
player.cpp
Code:
#include <string>
#include "Player.h"
void Player::setName(char* playerName){
_pstrPlayerName = playerName;
}
char* Player::getName(){
return _pstrPlayerName;
}
world.h
Code:
#ifndef WORLD_H
#define WORLD_H
class World {
public:
World();
char* getName();
protected:
char* _pstrWorldName;
};
#endif
world.cpp
Code:
#include "World.h"
World::World(){
_pstrWorldName = "Something";
}
char* World::getName(){
return _pstrWorldName;
}
Output:
Code:
World Name = Something
What is your name?
Stuff
Process returned -1073741819 (0xC0000005) execution time : 14.163 s
Press any key to continue.
If I comment out the two lines referring to World, it runs with no errors.