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
So it should be so that the role of copy constructor is performed by overloaded assignment operator?
The screen displays 1, i.e. the copying constructor is executed.
I think it's this: "2) uncommenting a stop with an overloaded assignment operator" is not supposed to help.
I don't know what is correct, but the assignment operator in VS does not perform the role of the copy constructor.
The screen displays 1, i.e. the copy constructor is running.
I think this: "2) uncommenting a stop with an overloaded assignment operator" should not help.
The copy constructor is executed here
not inside the fn() function.The copy constructor is performed here
and not inside the fn() function.In this variant:
The line "Assignment constructor is executed" is not output.And that's how it's deduced:
WWer, if by analogy with VS, you need to look at the specific situation, give a specific example of copying/assignment. What will be executed is decided on the spot.Why should it be initialised? It's an instance of a class that has a constructor for just that purpose.
And how to write a correct copying constructor for this purpose?
Your function getCopy() that is trying to return the object is quite correctly written. After overriding the assignment it already returns a pointer, the error evaporates.
--
The confusion here may be caused by the fact that the language has some "syntax backlash", associated with the same syntax representation of accessing the fields of a static object and a dynamic one (with a point instead of an arrow, which, by the way, is really convenient). This is very commonplace, and can somewhat blunt the distinction between objects and object pointers, which in turn can lead to some illusions, such as that something can be assigned to a static (or automatic) object variable. Far from it, an object variable to the left of an assignment is always a pointer, if the copy constructor is not defined.
C++ constructs q2 object inside fn() function in return, that's why copy constructor works.
In MQL5, the object is constructed from the outside, so there are differences. Let's eliminate them.
For those who are interested: it's called Return value optimization
Colleagues, good day!
Can you tell me how I can get price values for different financial instrumentsin sync? I mean, for example, closing prices of bars at a certain point in time in the past on different instruments. The use of CopyClose function and getting the values by index of bars is not absolutely correct, because there can be some missed bars for different instruments. As far as I remember, mql4 has the BarShift function by time, is there an analogue on mql5?
If you know the time, you can use this function.
Addressing by start date and number of items required
intCopyClose(
stringsymbol_name,// symbol name
ENUM_TIMEFRAMEStimeframe,// period
datetimestart_time,// from whichdate
intcount,// how many we copy
doubleclose_array[]// array for copying closing prices
);
If you know the time, you can use this function.
Refer to the start date and number of items required
intCopyClose(
stringsymbol_name,// symbol name
ENUM_TIMEFRAMEStimeframe,// period
datetimestart_time,//from what date
intcount,// how many we copy
doubleclose_array[]// array for copying of closing prices
);
Suppose, I want to find ratio of close[i] EUR/USD and close[i] GBP/USD, but if I use index i, the bars may be different in time anyway, because there are some missed bars.
In other words, I have to use CopyClose(Symbol, 0, date_of_current_bar, 1, array) in cycles for each bar ?
It seems to me, that bars of older TF rarely "disappear".
Another variant is to obtain the time of this bar simultaneously through CopyTime().
And third option (probably easiest) use CopyRates in structure at once.