Did I Use Delete Correctly?
Hello, I been working on my text game again and unsure if I used Delete Correctly. Someone Suggested I use:
Code:
Player::~Player()
{
for(int i=0;i<rows;i++){
delete [] SpaceName[i];
}
delete [] SpaceName[i];
}
But it didnt work. Here is my Code.
Code:
#pragma once
#include "Player.h"
class Space{
public:
void SetDescription(string);
string GetDescription();
Space();
~Space();
void CreateSpace(int,int);
private:
string Description;
Space **SpaceName;
int rol;
int col;
};
Space::Space(){};
void Space::CreateSpace(int rol,int col){
this->rol=rol;
this->col=col;
SpaceName = new Space*[rol];
for( int i=0;i<rol;i++){
SpaceName[i]=new Space[col];
}
};
Space::~Space(){
for( int i=0;i<rol;i++){
delete [] SpaceName[i];
}
for(int x=0;x<col;x++){
delete[] SpaceName[x];
}
}
void Space::SetDescription(string Description){
this->Description=Description;
}
string Space::GetDescription(){
return Description;
}
Thank you for taking time to look at my problem. :)
Byebye From me. Have a Nice Day