Need some help here it seems to compile fine but crashes at runtime. Am I missing something here?
#include <iostream>
#include <string>
using namespace std;
// player class
class Player{
int *position;
public:
Player();
Player(int);
~Player();
void print_pos(){
cout << "player 1 is in position: " << *position << endl;
}
};
Player::Player(){ // main constructor
position = new int;
*position = 0;
}
Player::Player(int pos){ //overloaded constructor
*position = pos;
}
Player::~Player(){ // destructor
delete position;
}
int main()
{
Player one;
Player two(1);
one.print_pos();
two.print_pos();
return 0;
}