最近学到类,用类写一个计算工资的题目,题目写完了,但总是在运行结束后要等一段时间,然后返回值不是0而是一串很长的数,求大佬解惑
#include <iostream>
#include<cstdlib>
#include"payroll.h"
using namespace std;
int main()
{
int rate,hour,counts=0;
payroll*p=new payroll[7];
payroll*s=p;
for(counts=0;counts<7;counts++,p++)
{
cout<<"enter the hourly pay rate of employee "<<counts+1<<":";
cin>>rate;
cout<<"enter the working hour of employee "<<counts+1<<":";
cin>>hour;
if (hour < 0)
{
cout <<"NO NEGATIVE HOURS ARE ALLOWED\n ";
counts--;
}
if (hour> 60)
{
cout <<"Valid hours are from 0 - 60\n ";
counts--;
}
(*p).Sethour(hour);
p->Setrate(rate);
}
for(counts=0;counts<7;counts++,s++)
{cout<<"The gross of employee "<<counts+1<<"is: "<<s->gross()<<endl;}
delete []p;
p=NULL;
return 0;
}
我的destructor里有设置cout<<"success!";可是并没有显示,是不是说明没有成功地删除