It is very simple. I think it is desirable to take this phenomenon into account when writing optimal code. Some people don't think so.
I think it is right for me to write about it in this thread. Someone does not think so.
I don't mind, but it's just desirable to see such explanations at once so that such questions don't arise. But now you read it and think: "What is this about?". And as for the optimal code, I think it is the worst thing to pick through history. Though it's for amateurs...
I don't mind, but it's just desirable to see such explanations at once so that such questions don't arise. Otherwise, you read it and think: "What's this about?". And as for the optimal code, I generally consider it the worst thing to dig into history. Though it's for amateurs...
Is there any way to learn history without picking at history? Give me a hint.
In the case of two pointers, I would explicitly call operator= just in case😅
Although, with two pointers that's probably the only way to call operator=
Yes.
class A
{
public:
voidoperator =( const A* ) { Print(__FUNCSIG__); }
};
voidOnStart()
{
A* a = new A;
a = a; // Хорошо, что не принтует.
a.operator=(a); // Принтует, как надо.delete a;
}
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.
Then what's unusual, special about it?
Everything is very simple. I think it is desirable to take this phenomenon into account when writing optimal code. Someone does not think so.
I think it is right for me to write about it in this thread. Someone does not think so.
It is very simple. I think it is desirable to take this phenomenon into account when writing optimal code. Some people don't think so.
I think it is right for me to write about it in this thread. Someone does not think so.
I don't mind, but it's just desirable to see such explanations at once so that such questions don't arise. But now you read it and think: "What is this about?". And as for the optimal code, I think it is the worst thing to pick through history. Though it's for amateurs...
I don't mind, but it's just desirable to see such explanations at once so that such questions don't arise. Otherwise, you read it and think: "What's this about?". And as for the optimal code, I generally consider it the worst thing to dig into history. Though it's for amateurs...
Is there any way to learn history without picking at history? Give me a hint.
I noticed that the compiler does not swear at such a construction.
Of course, it is not a conversion of a pointer into an object, but in some situations such a construction is reasonable for speeding up.
What is the difference between
from
for that particular code?
[edit]
Doesn't '&a' mean 'GetPointer(a)' ? And then the implicit operator= takes the reference.
- reference (automatic object initially) -->
- pointer (as a result of &) -->
- reference (pointer converted by compiler into a reference for passing to operator=(const A&))
I could be wrong, I haven't checked, but at first glance your code should work exactly as I described itIs there any way to know history without picking at history? Give me a hint.
It's a secret...)
Doesn't '&a' mean 'GetPointer(a)' ? And then the implicit operator= takes the reference.
- reference (automatic object initially) -->
- pointer (as a result of &) -->
- reference (pointer converted by compiler into a reference for passing to operator=(const A&))
I may be wrong, I haven't checked, but at first glance your code should work exactly the way I describedIt works exactly like that.
That's exactly how it works.
I can't understand the meaning of 'a = &a' for that particular example. Why not replace it with 'a = a' ?
[edit]
In the case of two pointers, I would explicitly call operator= just in case😅
Although, with two pointers this is probably the only way to call operator=I can't understand the meaning of 'a = &a' for that particular example. Why not replace it with 'a = a' ?
In the case of two pointers, I would explicitly call operator= just in case😅
Although, with two pointers that's probably the only way to call operator=Yes.
Example.
I get it. I'd probably prefer to wrap in a method. Although this particular dodgy test shows that your option of copying the object is a bit faster.