C++left operand must be l-value

C++left operand must be l-value
#include
class CA
{
public:
double *p;
int n;
public:
CA(int n1)
{n=n1;p=new double[n];}
~CA()
{delete []p;}
CA(CA &t)
{n=t.n;p=t.p;}
double operator[](int i)
{return p[i];}
};
void main()
{
CA t(5);
double sum=0,d;
for(int i=0;i>d;
t[i]=d;
sum+=t[i];
}
CA s(t);
cout
glistne 1年前 已收到1个回答 举报

我云佐 幼苗

共回答了20个问题采纳率:90% 举报

operator[]返回的是一个临时变量
改:
double& operator[](int i)
{
return p[i];
}

1年前

6
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 4.381 s. - webmaster@yulucn.com