Download MetaTrader 5
To add comments, please log in or register
Publish your article. Millions of traders are looking for good ideas!
Pawel Wojnarowski
685
Pawel Wojnarowski 2012.03.16 21:44 

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?

Pawel Wojnarowski
685
Pawel Wojnarowski 2012.03.21 20:36  
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.
Rashid Umarov
Admin
11709
Rashid Umarov 2012.03.22 09:43  
Enigma71fx:

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

Just for safe reason.
Pawel Wojnarowski
685
Pawel Wojnarowski 2012.03.22 16:56  
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.
Rashid Umarov
Admin
11709
Rashid Umarov 2012.03.22 17:22  
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.
Pawel Wojnarowski
685
Pawel Wojnarowski 2012.03.22 18:32  
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.
/
To add comments, please log in or register