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
How do I return a reference in function parameters?
This kind of code causes problems:
CMy* obj; // global bool func(CMy* obj) { ... obj = new CMy(); ... }
Invalid pointer access when trying to work with obj.
Tried adding an &.
It works. I didn't find the reference return in function parameters in the documentation.
By analogy, I found this topic in C++: http://stackoverflow.com/questions/5286453/returning-a-pointer-as-a-function-parameter
But ** does not work here. *& instead of it?
5.00.630 x64
Return reference in function parameters was not found in the documentation.
How do I return a reference in function parameters?
This kind of code causes problems:
Invalid pointer access when trying to work with obj.
Tried adding an &.
It works. I didn't find the reference return in function parameters in the documentation.
By analogy, I found this topic in C++: http://stackoverflow.com/questions/5286453/returning-a-pointer-as-a-function-parameter
But your ** doesn't work. *& instead of it?
5.00.630 x64
IMHO (it was long ago).
You cannot pass a pointer through arguments but create a reference. You cannot bind a new instance of a class to a reference. That leaves the following way:
I am a proponent of OOP, because I have understood the convenience of programming from the bottom up. From object interaction interfaces to class implementation.
IMHO (it was a long time ago).
You cannot pass a pointer through arguments, you can create a reference. A new instance of the class cannot be attached to the reference. That leaves us with this option:
I have defined the question incorrectly.
Passing a pointer by reference. I'm wondering if one may use the *& variant and won't they cover it in further versions? In C++, such a construct seems to be legal.
You're referring to it: MQL5 Reference Guide / Language Basics / Data Types / References. Modifier & and keyword this?
I wish there was the right information...
In the article
https://www.mql5.com/ru/docs/basis/function/ParameterPass
you can also add information about working with objects.
Isn't an interface external to the class?
What difference does it make for objects? An interface in this interpretation is a data type, because its description clearly enough defines the properties of objects. And, in fact, it defines the external behaviour of objects.
In the materials I cited, the opponents of OOP mentioned that it is impossible to create the class structure immediately without implementing the algorithm, which is why the OOP environment so often practises refactoring and why classes slow down development with their eternal redesigning. And this is really true. When you implement something new and don't understand what it can lead to, you have to redo classes and more than once.
Creating a good class architecture is a stumbling block for beginners. In essence, the point of OOP programming is to write your own"language", a language that is easy and fast to create in the future. Interface is the essence of a language which is designed for the task. Interface, as a matter of fact, must not be understood as a construction "of type" of the class, as a contract for the class, which must be executed in code (in MQL, it doesn't exist and the role of interface can be feebly performed by virtual methods).
For example, you can create a "language" for creation of new EAs that allows you to assemble the general scheme of EAs from objects in a few lines. Signals and conditions can be used ready-made, or you can develop your own classes of signals and create your own library by analogy. This possibility is provided by MQL5 Wizard.
Often, the application's scheme has already been developed and "OOP programming" essentially boils down to the use of existing classes with limited degrees of freedom for writing your own functionality - this is convenient. This is why frameworks are so popular. They eliminate unnecessary problems and headaches when developing application architecture. In fact, writing something of your own is creating an heir class of one of the framework classes, and writing implementation of certain backend methods in it, which are already built into the overall application logic (OnInit, OnTick, for example).
...
Creating a competent class architecture is a stumbling block for beginners. In essence, the point of OOP programming is to write your own"language", a language that is easy and fast to create in the future. Interface is the essence of a language which is designed for the task. Interface should not be understood as a construct of "type" of the class, as a contract for the class, which must be executed in code (in MQL, it does not exist, and the role of interface can be validated by virtual methods).
...
Rather, the point of OOP is to write your own architecture. As soon as we have a clear, concise, intuitive architecture, everything falls into place and neither the complexity of the project nor its scope are any more constraining factors. However in order to achieve this very clear architecture you have to rewrite classes one by one getting closer to this initially vague ideal.