If the assignment works in the first case, logically it should work in the second one as well. Because in the first case the same rvalue is assigned to the pointer, but the operator then works!
This is just my opinion, of course. But I want to make it out.
I don't understand it either. )) Upd. Already got it.
If assignment works in the first case, it should logically work in the second one as well. That's because in the first case, the same rvalue is assigned to the pointer but the operator works after that!
This is, of course, just my opinion. But I want to make it out.
rvalue can only be assigned to a left-handed value or be a temporary constant.
This is what works in the pluses:
class A
{
public:
int m[10];
int& operator [] (constint i)
{
return((m[i]));
}
};
int main()
{
A oA;
oA[2] = 5;
}
This one doesn't.
class A
{
public:
int* m[10];
int* operator [] (constint i)
{
return((m[i]));
}
};
int main()
{
A oA;
oA[2] = newint; // error C2106: =: левый операнд должен быть левосторонним значением
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Stupid. Can you tell me why you can't do that?
Got it.
Explain
Explain
here[0] is rvalue.
This is what is not clear.
If the assignment works in the first case, logically it should work in the second one as well. Because in the first case the same rvalue is assigned to the pointer, but the operator then works!
This is just my opinion, of course. But I want to make it out.
That's what I don't understand.
I don't understand it either. )) Upd. Already got it.
If assignment works in the first case, it should logically work in the second one as well. That's because in the first case, the same rvalue is assigned to the pointer but the operator works after that!
This is, of course, just my opinion. But I want to make it out.
rvalue can only be assigned to a left-handed value or be a temporary constant.
This is what works in the pluses:
This one doesn't.
This one isn't, and I can't figure out the difference:
If you add a link to the pointer it will work. Or a double pointer.
Oops, I'm slowing down, the second example isn't right at all.
That's why it is logical that
error: invalid initialization of non-const reference of type 'int*&' from an rvalue of type 'int*'