Descriptor vs. pointer in MQL5 - question to MetaQuotes

 

Hi,

While browsing MQL5 reference, I have found such description in the section MQL5 Reference / Language Basics / Data Types / Object Pointers:

 

 Object Pointers

In MQL5, there is a possibility to dynamically create objects of complex type. This is done by the new operator, which returns a descriptor of the created object. Descriptor is 8 bytes large. Syntactically, object descriptors in MQL5 are similar to pointers in C++.

Examples:

MyObject* hobject= new MyObject();

Again, unlike C++, the variable hobject from the example above is not a pointer to the memory, it is a descriptor of the object.

 

MetaQuotes: could you please give some insight on it? Why is this difference (in comparison to C++) introduced?

 
MetaQuotes: is it a secret or what? No-one has replied this question for 5 days. I guess that as you are the creators of the MQL5 language, you could easily tell the reason behind such approach.
 
Enigma71fx:

MetaQuotes: could you please give some insight on it? Why is this difference (in comparison to C++) introduced?

Just for safe reason.
 
Rosh:
Just for safe reason.
What kind of safe reason? E.g. to avoid situation, in which pointer could point to a wrong place in memory? Sorry for bothering you, but I am asking out of curiosity.
 
Enigma71fx:
What kind of safe reason? E.g. to avoid situation, in which pointer could point to a wrong place in memory?
Yes, you are right.
 
Rosh:
Yes, you are right.

That's what I supposed. Thanks, Rosh! Forum users can always count on you :)

 

 By the way - as you have appeared on the forum - may I ask you for a comment on a different thread, related to declaring static class members? -> https://www.mql5.com/en/forum/1395  This seems like a major drawback, comparing to C++. It is really difficult and uncomfortable to implement some OOP techniques without it.

MQL5: How to declare a (static) member/class variable?
  • www.mql5.com
The example code is attached.