A
andylcx
Hi all, I have a question about the code below. Any idea abuot that,
thanks in advance!
myclass.h
class myclass
{
public:
myclass();
~myclass();
void setdata();
private:
yclass *ypr;
};
myclass.cpp
include"myclass.h"
include"yclass.h"
myclass::myclass()
{
yclass *ypr=new yclass;
}
myclass::~myclass()
{
delete ypr;
}
void myclass::setdata()
{
yclass *newpr=new yclass;
ypr=newpr; //My question is here. If I delete the "*ypr" pointer in
the destructor function of myclass, does the "*newpr" pointer being
deleted automatically since both of them have the same address? the
newpr class object has the same lifetime as myclass(after it was
created), and I have no idea when it should be deleted.
}
thanks in advance!
myclass.h
class myclass
{
public:
myclass();
~myclass();
void setdata();
private:
yclass *ypr;
};
myclass.cpp
include"myclass.h"
include"yclass.h"
myclass::myclass()
{
yclass *ypr=new yclass;
}
myclass::~myclass()
{
delete ypr;
}
void myclass::setdata()
{
yclass *newpr=new yclass;
ypr=newpr; //My question is here. If I delete the "*ypr" pointer in
the destructor function of myclass, does the "*newpr" pointer being
deleted automatically since both of them have the same address? the
newpr class object has the same lifetime as myclass(after it was
created), and I have no idea when it should be deleted.
}