You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Come on! I use it all the time.
Where? In what place and how?
Moderators, sorry for repeating the question. I really want to get an answer to it.
Why would you intentionally reassign a pointer passed to a function? Of course, there will be a leak. But this is not a "classic leak", but a classic error of working with a pointer to an object.
You don't have to create a new object here, but handle the external object the pointer to which was passed into the function.
Where? In what place and how?
Moderators, sorry for repeating the question. I really want to get an answer to it.
Where? In what place and how?
Moderators, sorry for repeating the question. I really want to get an answer to it.
If I understand the question correctly, we declare the class as an object using new.
Then use a point to call public methods of the class through the created object.
After all called methods are executed, we clear the memory by deleting the created object delete.
If I've understood the question correctly, we declare the class as an object using new.
Then we call the public methods of the class through the created object, using a dot.
After all called methods are executed, we clear the memory by deleting the created object delete.
Nope. At first I thought it was a function parameter like this - object but not by reference, but there's a semicolon at the end. If it's a normal object creation at declaration, then why is it in brackets? So for now it remains the mystery of the century.
Nope. At first I thought it was a function parameter like this - object but not by reference, but there's a semicolon at the end. If it's a normal object creation at declaration, then why is it in brackets? So for now it remains the mystery of the century.
And why have you deliberately reassigned a pointer passed to a function? Of course, there will be a leak. But it's not a "classic leak", but a classic error of handling a pointer to an object.
You need not create a new object here but handle the external object the pointer to which was passed into the function.
It's not about my example, it's about the implementation of the pointers themselves in MQL - if you don't need to dereference them (and the pointer can be assigned to an instance of the object!), if instead of passing a pointer you can pass a reference to the objecthttps://www.mql5.com/ru/forum/1111/page2471#comment_11796665
here we have no detailed information about where and when (CObj& obj) appeared (& is not a pointer dereferencing operation, but acquisition of a pointer GetPointer() )
Ok, I don't want to waste any information... I've already told myself, and I'll repeat it once again in this forum - MQL is not C++, that's how it's implemented - well, I have no other options
It's not about my example, it's about the implementation of the pointers themselves in MQL - if you don't need to dereference them (and the pointer can be assigned to an instance of the object!), if instead of passing a pointer you can pass a reference to the object https://www.mql5.com/ru/forum/1111/page2471#comment_11796665
here we have no detailed information about where and when (CObj& obj) appeared (& is not a pointer dereferencing operation, but acquisition of a pointer GetPointer() )
Ok, I don't want to waste any information... I've already told myself, and I'll repeat it once again in this forum - MQL is not C++, that's how it's implemented - well, I have no other options
You're being dramatic, there are no complexities and confusions.
The brackets are because this is a note on the text))))
So there you go.
Like this:
void z(CObj * o){ }
Not even just can, but better, because you can call it like this:
z(GetPointer(obj));
If you pass a pointer by reference, you need another variable for the pointer.
***
And if a pointer needs to be passed to a function to create an object in the function, this is how it works:
That's basically all you wanted to know about OOP, but were afraid to ask)))