Without the name, it runs fine. I read up that adding const before new could solve my problem, but it doesn't. Any ideas?
include <iostream>
include <string.h>
using namespace std;
class Player {
int Health, *Strength, *Speed, *Accuracy, *Defense;
char *Name[80];
public:
Player (char, int, int, int, int, int);
~Player ();
void Manip (int, int, int, int, int);
void Output ();
};
Player::Player (char Nme, int Hth, int Str, int Spd, int Acc, int Dfn) {
Name = new char[80];
Health = new int;
Strength = new int;
Speed = new int;
Accuracy = new int;
Defense = new int;
*Name[80] = Nme[];
*Health = Hth;
*Strength = Str;
*Speed = Spd;
*Accuracy = Acc;
*Defense = Dfn;
}
Player::~Player () {
delete Health;
delete Strength;
delete Speed;
delete Accuracy;
delete Defense;
}
void Player::Manip (int A, int B, int C, int D, int E) {
*Health = *Health + A;
*Strength = *Strength + B;
*Speed = *Speed + C;
*Accuracy = *Accuracy + D;
*Defense = *Defense + E;
}
void Player::Output () {
cout << "\nHealth: " << *Health << endl;
cout << "Strength: " << *Strength << endl;
cout << "Speed: " << *Speed << endl;
cout << "Accuracy: " << *Accuracy << endl;
cout << "Defense: " << *Defense << endl << endl;
}
int main () {
Player Player1 ("Player One", 100, 20, 20, 20, 20), Player2 ("Player Two", 500, 100, 100, 100, 100);
Player1.Player::Output();
Player2.Player::Output();
Player1.Player::Manip (10, 10, 10, 10, 10);
Player2.Player::Manip (20, 10, 10, 20, 10);
Player1.Player::Output();
Player2.Player::Output();
return 0;
}