Questions on OOP in MQL5 - page 5

 
 
Vladimir Simakov:
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.

 
Artyom Trishkin:

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.

This is not me. It is taken from somebody else's code on this thread. It's taken as an example.
 
Dmitry Fedoseev:

Where? In what place and how?

Moderators, sorry for repeating the question. I really want to get an answer to it.

Have patience. I'll get home and post it.
 
Dmitry Fedoseev:

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.

 
Roman:

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.

 
Dmitry Fedoseev:

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.

In brackets - because it is a note on the text))))
 
Artyom Trishkin:

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

 
Igor Makanu:

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.

 
Vladimir Simakov:
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:

CObj obj;
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:

class CObj{
   public:
   int f(){
      return(33);
   }
};

CObj * obj;

void OnStart(){
  z(obj);
  delete(obj);
}

void z(CObj & o){
   o = new CObj();
}
That's basically all you wanted to know about OOP, but were afraid to ask)))
Reason: