this is the code i have for deep copying a string in copy constructor so is the logic correct??I think there may be memory leak and i am trying to fix that.m.pStatus is initialised
class Monkey
{
public:
// insert your code here
Monkey();
Monkey(const Monkey& m);
Monkey& operator=(const Monkey& m);
~Monkey();
// accessors
int getX();
int getY();
char *getStatus();
void deepCopy(const Monkey& m);
// global variables (incremented each creation or destruction)
static int numStringsCreated;
static int numStringsDestroyed;
private:
// Do not change this data
int x;
int y;
char *pStatus;
};
void Monkey::deepCopy(const Monkey& m)
{
if (m.pStatus)
{
// allocate memory for our copy
pStatus= new char[sizeof(m.pStatus)];
for (int i{ 0 }; i < sizeof(m.pStatus); ++i)
pStatus[i] = m.pStatus[i];
}
else
pStatus = nullptr;
}
Monkey::Monkey(const Monkey& m)
{
deepCopy(m);
numStringsCreated++;
}