I write a class
struct opera{
int a,b;
int op;
opera(int a1=0,int b1=0,int op1=-1):a(a1),b(b1),op(op1){}
opera& operator=(opera& tmp){
a=tmp.a;
b=tmp.b;
op=tmp.op;
}
And I want to assign it to an array element like this:
ans[a][b]= opera(t.a,t.b,i);
Why it can’t compile successfully.
However this can work:
opera tmp=opera(t.a,t.b,i);
ans[a][b]= tmp;
Of course,the struct opera don’t need a explicit assignment function, and
ans[a][b]= opera(t.a,t.b,i);
can work directly.
When you want to assign from a temporary, you need
The other line
is an initialization of a new object, and not an assignment.