最後の行でなぜ*newP; を返すのかわかりません。Poly
コピー コンストラクターから新しく作成されたコンストラクターを解放できないため、メソッドをコピー コンストラクターに入力すると、メモリ リークが発生しますか?
const Poly Poly::operator * (const Poly &p1) const {
Poly* newP= new Poly;
delete newP->headList->mono;
newP->headList->mono=NULL;
delete newP->headList;
newP->headList=NULL;
newP->SetCount(0);
//two pointer to run on the list
Node* tmp,* tmp2;
tmp= this->headList;
tmp2=p1.headList;
Mono* mono= new Mono;
int n,d,p;
while (tmp != NULL)
{
while (tmp2!=NULL)
{
*mono=(*tmp->mono)*(*tmp2->mono);
n=mono->GetiNom();
d=mono->GetiDenom();
p=mono->GetPower();
newP->Insert(n,d,p);
tmp2=tmp2->next;
}
tmp=tmp->next;
tmp2=p1.headList;
}
delete mono;
return *newP;
}