我的程序为什么运行出错啊!(operator has no effect; expected operator with side-effect)
class shape
{
public:
virtual float area()=0;
};
class rectangle:public shape
{
private:
float H,W;
public:
float area()
{return H*W;}
rectangle(float h,float w)
{
H=h,W=w;
}
};
class circle:public shape
{
private:
float R;
public:
circle(float r)
{
R=r;
}
float area()
{
return 3.14 *R*R;
}
};
#include <iostream.h>
#include "area.h"
void sort(shape *a[],int n)
{
shape *ptr;
for (int i=0;i<n;i++)
for(int j=1;j<=n;j++)
{
a[i]->area() > a[j]->area();
ptr=a[i];
a[i]=a[j];
a[j]=ptr;
}
}
float total(shape *a[],int n)
{
float sum=0.0;
for(int i=0;i<n;i++)
{
sum+=a[i]->area();
}
return sum;
}
void show(shape *a[],int n)
{
for(int i=0;i<n;i++)
cout<<"the arear of the shape"<<a[i]->area()<<endl;
}
int main()
{
float sum;
circle C1(3.0),C2(2.0);
rectangle R1(2.0,1.0),R2(1.0,3.0);
shape *sp[4];
sp[0]=&C1;sp[1]=&C2;
sp[2]=&R1;sp[3]=&R2;
sort(sp,4);
show(sp,4);
sum=total(sp,4);
cout<<"the total area is :"<<sum<<endl;
return 0;
}
问题是在红题字部分总是出现operator has no effect; expected operator with side-effect的警告信息!高手帮忙啊!