Hi from what I have seen this should be correct but compiler is complaining.
#include <iostream>
#include <string>
using namespace std;
// player class
class Player{
int *position;
string name;
public:
Player();
~Player();
void set_name(){
cout << "enter name: ";
getline(cin,name);
cout << "name is now: " << name << endl;
}
void print_pos(){
cout << name << " is in position: " << *position << endl;
}
void set_pos(int pos){
*position = pos;
}
};
Player::Player(){ // main constructor
position = new int;
*position = 0;
set_name();
}
Player::~Player(){ // destructor
delete position;
}
int main()
{
int num_players = 0;
int exit = 9;
while(exit != 9){
cout << "1. Create player\n9. Exit\n";
cout << "Choice: ";
cin >> exit;
if(exit == 1){
num_players += 1;
Player* player = new Player[num_players];
}
delete[] player;
}
return 0;
}
error C2065: 'players' : undeclared identifier
error C2541: 'delete' : cannot delete objects that are not pointers
Thank you greatly for your time.