0

C2106: '=' : left operand must be l-value の行でエラーが発生しましたが、 それ*shp[count]).area()=max;が何を意味するのかわかりません。形状クラスはすべての形状の基本クラスであり、それらすべてを形状タイプの配列に入れて、どれが最大の面積を持っているかを見つけようとしています

int largestArea()
{
float max =-99999;
int index = 0;
shape *shp[6];
shp[0 ]= new trapezoid (4,6,3);
shp[1 ]= new triangle  (4,2);
shp[2 ]= new parallelogram (3,8);
shp[3 ]= new trapezoid (2,6,3);
shp[4 ]= new triangle  (5,2);
shp[5 ]= new parallelogram (2,7);

for(int count=0;count<6;count++)
{
    if((*shp[count]).area()>=max)
    {
        (*shp[count]).area()=max;
        index = count;
    }
}

return index;   
4

2 に答える 2

4

を割り当てるつもりmaxでした。これを試して:

max = (*shp[count]).area();
于 2013-11-11T06:12:51.957 に答える
2

私は少し話題から外れていることを知っています。

これを書いてみませんか?

size_t index = 0; 
float max = (*shp[0]).area(); 

for(int count=1;count<6;count++)
{
    if((*shp[count]).area()>=max)
    {
        max = (*shp[count]).area();
        index = count;
    }
} 

次のようなものを読む:

float max =-99999; 

不快です。

于 2013-11-11T06:26:05.160 に答える