![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Local variables and parameters are in the same scope, so - it doesn't matter if a parameter has this name or a local variable, but either way this name hides the name in the outer scope.
Not in any function. When a variable is passed by reference, a local copy is not created and operation is performed directly with the passed variable. So what kind of hiding is going on here?
This is where the hiding of names takes place. Everything else - copy, not copy - is secondary. Inside a function, when a reference name is used, the work will be done on the object the reference refers to. If it refers to an object in the outer scope, the work will be done with it. This is not because there is no name-hiding - the hiding is present, just as in other cases - but because the reference points to this object. A function is called this way. Passed on this very object by reference and it now points to it. When calling and passing at the moment of calling another object, the same function code will work with another object.
I was giving an example with a type name and a variable name, i.e. with entities that are as different in nature as possible, to show that hiding applies/references to names, and everything else is secondary.
However, when trying to create another example in MQL4++ on this theme, I accidentally discovered that an additional scope is created for parameters in MQL4++. The scope of local variables is already nested in it:
This example is COMPILED with a characteristic warning:
And later it is successfully executed:
It's obvious that another "layer" scope is created for parameters in MQL4++. This is why it is possible to declare a local variable with the same name as the parameter.
In C/C++ there is no such "layer":
The compiler explains popularly that there is already a variable with that name in the scope:
That is, the scope of function parameters and its local variables are one and the same.
Why it's not so in MQL4++ and for what purpose it's not - is, of course, an interesting question...
This example COMPILES with a characteristic warning:
This case discusses the case of passing a variable by reference and an erroneous warning, not the creation of a local copy.
I only read the first few posts.
Of course, things don't go quite smoothly under the mat either. There are some lapses of the developers here in testing the product that reaches the end user. However, also MT4 is not strong in multi-currency strategies (testing), and needs, needs to be refined. So I hope it will be someday, after all.
If you do not know how to program, do not go to the real one, and use the demo for now. As always a bad dancer gets in the way of "balls", including gold and pink.
Good luck!
This is a case of passing a variable by reference and an erroneous warning, not creating a local copy.
It doesn't really matter in terms of the nature of the warning. Moreover, it doesn't matter not only if a variable is passed by reference or by value, but what type it is:
The code compiles, the warning you're discussing is generated:
For some reason you don't want to understand that.
The warning itself is not at all erroneous. Moreover, at a quick glance, scope tracking in MQL4++ is surprisingly well done compared to how other things are done.
Warnings, while true, are not practical, and yet you can't turn them off - that's what it's all about. And by no means the transmission of the link.
In terms of the nature of the warning, this is irrelevant. Furthermore, it does not matter whether the variable is passed by reference or by value
There is a large difference in the essence of the warning between passing the variable itself and modifying it in a function and creating a copy of it, while the variable itself remains unchanged.
And the fact that the warnings can not be disabled or customized, it's a classic MC proprietary style - "do not let":))) There's nothing you can do about it, but you can only humbly and meekly accept it because this style has been elevated to the status of a religious attribute... There is no point in searching for logic or any kind of justice here. ))
Ugh ugh I have all the methaquot stuff working like clockwork.
No complaints at all.
A potential error is just that, a potential error is not necessarily an error at all. Therefore, the statement that "it means we have to fix these errors" is wrong, because they may NOT be errors at all.
...
But God forbid that you get an unmanageable code when there are no errors or warnings and the program seems to work well but strange bugs occur now and then, the reason for which cannot be found anywhere. At such moments you get covered with vapor and start dreaming about errors like "invalid pointer" or "division by zero".
The compiler has nothing to do with it, it is typical buggy programming when there are no test checks in dangerous code fragments where undefined or erroneous states are possible, that's why the glitches appear.
Functional code checks have nothing to do with the compiler and there is no point in expecting that from the beginning.
Again professional programmers usually don't look at the warnings because they know the compiler's logic while compilers are useless in checking code functionality.
There is a big difference in essence warnings between passing the variable itself and modifying it in a function and making a copy of it, while the variable itself remains unchanged.
Here it's just a different type of warning. About hiding names.
The variable itself is not passed. A reference to it is passed.