0

I'm getting a C2106: '=' : left operand must be l-value error on the line with *shp[count]).area()=max; and I'm not sure what that means. The shape class is a base class for all of the shapes and I'm trying to put them all in an array of type shape and find which one has the largest area

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;   
Adam
  • 16,808
  • 7
  • 52
  • 98
DaCat
  • 25
  • 1
  • 9

2 Answers2

4

You meant to assign max. Try this:

max = (*shp[count]).area();
Phillip Kinkade
  • 1,382
  • 12
  • 18
  • haha wow im an idiot this is the second time i did this i think this may be the problem..... thanks a lot that was the problem – DaCat Nov 11 '13 at 06:18
2

I know I'm slightly off-topic.

Why don't you write this?

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;
    }
} 

Reading things like:

float max =-99999; 

is unpleasant.

jimifiki
  • 5,377
  • 2
  • 34
  • 60