
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
I still don't understand about pointers and references in MQL5 and now in MQL4. What is the difference between passing by reference and pointer except for extra code? There is a difference in C++, but what is it here? If it is not difficult to write more detailed.
Passing by reference requires that the object passed by reference be initialised. Passing by pointer does not have this restriction:
When calling the TestShapeRef function, the code will crash because the shape is not initialised. On the other hand, inside the TestShapePointer function, constant checks are required whether the passed object is initialised or not. Therefore, follow the imprirical rule:
There is one more subtle nuance you should keep in mind. Consider the previous example:
Will this program work correctly? No, it will end with the error "invalid pointer access" at the line printf(shape.name); //ERROR (!?) , despite the fact that we seem to be guaranteed to create an object in the TestShapePointer function. The point is that in fact a NULL reference was passed instead of shape. That is, the shape inside the function and the passed shape are different objects! Thus, after exiting the function, shape is still equal to NULL, and the shape pointer inside the function is lost (cleared in the stack). So.Is it possible to create an array with objects of different types?
Let's take this example:
//---
How to get access to methods of inherited classes?
How to access methods of inheritor classes?
Have you tried casting a target type?
No. This is the first I've heard of it. Where can I read about it?
The usual type conversion, here's an example:
Have you tried casting to the target type?
Shit, and you're talking about language security after that?
Wouldn't it be better to use polymorphism?
It goes something like this: