我收到 C2106: '=' : left operand must be l-value
错误
*shp[count]).area()=max;
我不确定那是什么意思。 shape 类是所有形状的基类,我试图将它们全部放在一个 shape 类型的数组中,并找出哪个具有最大的面积
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;
最佳答案
您打算分配 max
。试试这个:
max = (*shp[count]).area();
关于c++ - 错误 C2106 : '=' : left operand must be l-value c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19899913/