c++ - 错误 C2106 : '=' : left operand must be l-value c++

标签 c++ inheritance polymorphism dynamic-memory-allocation lvalue

我收到 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/

相关文章:

c++ - 为什么 CString::LoadString 在我的应用程序的主模块 (.exe) 中工作,但在我的 extensionDLL 中不工作?

c# - 为什么在显式 getter-only 接口(interface)实现上使用私有(private) setter 是非法的?

c# - 继承模板抽象类C#

c# - XmlRootAttribute 是否可继承?

c++ - 在这种情况下,哪种设计模式可以很好地实现运行时多态性?

java - 说接口(interface)也是一种类型是什么意思?

c++ - 使用 boost::asio 是否有一种可移植的方法来查找空闲端口号

c++ - 是否已初始化静态 char[] 缓冲区

c++ - 以优雅的方式进行二进制比较操作

java - 需要对这种通用类型进行简要描述